SnakeYaml dump automatically converts numbers(represented as Strings)

Viewed 669

I am using yaml dump method to create a configuration file for my object. I have the following code:

Map<String, String> map = new HashMap<>();
map.put("phonenumber","7285042388");
map.put("name","Cristina");
DumperOptions dumperOptions1 = new DumperOptions();
dumperOptions1.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml2 = new Yaml(dumperOptions);
System.out.println(yaml2.dump(map));`

Output:

phonenumber: '7285042388'

name: Cristina

I want the phone number to be shown without single quotes. I've noticed that using a map with Object type for values solves this, but I need the values type to be String. How could I solve this?

1 Answers
Map<String, Object> map = new HashMap<>();
map.put("phonenumber",  new BigInteger("7285042388"));
map.put("name","Cristina");
DumperOptions dumperOptions1 = new DumperOptions();
dumperOptions1.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml2 = new Yaml(dumperOptions1);
System.out.println(yaml2.dump(map));

Output:

phonenumber: 7285042388
name: Cristina
Related