0

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.

BlueChips23
  • 1,861
  • 5
  • 34
  • 53
  • 1
    Possible duplicate of [How to serialize fields with custom names using snake yaml in Java](https://stackoverflow.com/questions/54351787/how-to-serialize-fields-with-custom-names-using-snake-yaml-in-java) – flyx Sep 28 '19 at 06:26
  • 1
    As mentioned in comments on my answer of the other question, this is currently not possible due to [this issue](https://bitbucket.org/asomov/snakeyaml/issues/403/typedescriptionsubstituteproperty-doesnt). – flyx Sep 28 '19 at 06:27

0 Answers0