I have a POJO that looks like this:
public class Foo {
private String barA;
private String barB;
public void setBarA(String barA) {
this.barA = barA;
}
public void setBarB(String barB) {
this.barB = barB;
}
public String getBarA() {
return barA;
}
public String getBarB() {
return barB;
}
}
My code to convert this into YAML looks like this:
Representer representer = new Representer();
representer.addClassTag(Foo.class, tag.MAP);
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(representer, options);
StringWriter writer = new StringWriter();
yaml.dump(foo, writer);
The output of this using SnakeYAML looks like this:
barA
barB
However, in the output, I want the naming convention of the variables to look like this:
bar_a
bar_b
How do I accomplish that with SnakeYAML? I want to clarify that I do not want to change the naming convention of my Java variables. I believe this is probably possible using TypeDescription
or some sort of serialization, but I'm not sure how exactly to do this.