小编Laa*_*Laa的帖子

如何在snakeyaml中隐藏bean类型

此代码将输出:(YAML)

--- !! org.test.bean.Person

地址:4011 16th Ave S.

.....

无论如何都可以隐藏我的bean类型(org.test.bean.Person)!(更喜欢使用snakeyaml配置...我找不到它..)

谢谢!!

public static void dumpYAML(){
    Constructor constructor = new Constructor(Person.class);
    TypeDescription personDescription = new TypeDescription(Person.class);
    personDescription.putListPropertyType("phone", Tel.class);
    constructor.addTypeDescription(personDescription);

    Yaml yaml = new Yaml(constructor);
    Person person = (Person) yaml.load(makeYAML());

    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
    options.setCanonical(false); // display bean member attribute
    options.setExplicitStart(true); // display --- start

    yaml = new Yaml(options);
    String output = yaml.dump(person);
    System.out.println(output);
}
Run Code Online (Sandbox Code Playgroud)

java yaml snakeyaml

5
推荐指数
2
解决办法
2763
查看次数

标签 统计

java ×1

snakeyaml ×1

yaml ×1