我正在使用yaml dump方法为我的对象创建配置文件。我有以下代码:
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));`
输出:
phonenumber: '7285042388'
name: Cristina
我想要显示的电话号码没有单引号。我注意到使用带有Object类型的映射来解决这个问题,但是我需要将值类型设置为String。我怎么能解决这个问题?
答案 0 :(得分:0)
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));
输出:
phonenumber: 7285042388
name: Cristina