簡體   English   中英

SnakeYaml dump 自動轉換數字(表示為字符串)

[英]SnakeYaml dump automatically converts numbers(represented as Strings)

我正在使用 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。 我怎么能解決這個問題?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM