SnakeYaml保留bean属性名称的大小写

时间:2017-10-27 12:36:13

标签: java yaml snakeyaml

在snakeyaml中,我需要保留bean属性名称。

我有跟随豆。

    public class MyBean{

        private String Name;
        private String Param;

        //getter and setter methods.
    }

现在,当我使用以下内容转储此bean时。

public class TestClass {

public static void main(String args[]) {
    MyBean myBean = new MyBean();
    myBean.setName("Foo");
    myBean.setParam("Bar");

    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);

    Representer representer = new Representer();
    representer.addClassTag(MyBean.class, Tag.MAP);

    Yaml yaml = new Yaml(representer, options);

    String output = yaml.dump(myBean);
    System.out.println(output);

}
}

输出:

name: Foo
param: Bar

但我想要的是:

Name: Foo
Param: Bar

0 个答案:

没有答案