This code will output:(YAML)
--- !!org.test.bean.Person
address: 4011 16th Ave S
.....
Can hide my bean type(org.test.bean.Person) anyway !? (prefer to use snakeyaml config...i can't find it..)
thanks!!
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);
}
Use org.yaml.snakeyaml.representer.Representer, set Tag.MAP to hide the root tag.
Representer representer = new Representer();
representer.addClassTag(Person.class, Tag.MAP);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With