apache / dubbo-admin

@@ -17,36 +17,40 @@
Loading
17 17
18 18
package org.apache.dubbo.admin.common.util;
19 19
20 +
import org.apache.dubbo.common.utils.PojoUtils;
20 21
import org.yaml.snakeyaml.Yaml;
22 +
import org.yaml.snakeyaml.constructor.SafeConstructor;
23 +
import org.yaml.snakeyaml.error.YAMLException;
21 24
import org.yaml.snakeyaml.introspector.Property;
22 25
import org.yaml.snakeyaml.nodes.NodeTuple;
23 26
import org.yaml.snakeyaml.nodes.Tag;
24 27
import org.yaml.snakeyaml.representer.Representer;
25 28
26 -
public class YamlParser {
27 -
28 -
    private static Yaml yaml;
29 -
30 -
    static {
31 -
        Representer representer = new Representer() {
29 +
import java.util.Map;
32 30
33 -
            protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, Tag customTag) {
34 -
                if (propertyValue == null) {
35 -
                    return null;
36 -
                }
37 -
                else {
38 -
                    return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
39 -
                }
40 -
            }
41 -
        };
42 -
        yaml = new Yaml(representer);
43 -
    }
31 +
public class YamlParser {
44 32
45 33
    public static String dumpObject(Object object) {
46 -
        return yaml.dumpAsMap(object);
34 +
        return new Yaml(new SafeConstructor(), new CustomRepresenter()).dumpAsMap(object);
47 35
    }
48 36
49 37
    public static <T> T loadObject(String content, Class<T> type) {
50 -
        return yaml.loadAs(content, type);
38 +
        Map<String, Object> map = new Yaml(new SafeConstructor(), new CustomRepresenter()).load(content);
39 +
        try {
40 +
            return (T) PojoUtils.mapToPojo(map, type);
41 +
        } catch (Exception e) {
42 +
            throw new YAMLException(e);
43 +
        }
44 +
    }
45 +
46 +
    public static class CustomRepresenter extends Representer {
47 +
48 +
        protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, Tag customTag) {
49 +
            if (propertyValue == null) {
50 +
                return null;
51 +
            } else {
52 +
                return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
53 +
            }
54 +
        }
51 55
    }
52 56
}
Files Complexity Coverage
dubbo-admin-server/src/main/java/org/apache/dubbo/admin 18.98% 20.41%
Project Totals (97 files) 18.98% 20.41%

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading