Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to convert yaml string to map with key "NO" in java

Tags:

java

rest

yaml

While I am trying to convert yaml string to Map I am getting key change.
YAML File:-

---
HK: 
  isp: 
    Airtel: AirtelChennal
  www.enemalta.com: 
    default: defaultEma
    user1: chennal1
  studiodefault: hkDefaultchennal
  country: 
    DK: denmarkChennal
    NO: chennal2

Java code:-

Yaml yaml= new Yaml();
Map<String,Object> map= (Map<String, Object>) yaml.load(yamlString);

output :-

{HK={isp={Airtel=AirtelChennal}, www.enemalta.com={default=defaultEma, user1=chennal1}, studiodefault=hkDefaultchennal, country={DK=denmarkChennal, false=chennal2}}}

in above output false is replace with "NO", but I need "NO" as it is.

Expected output:-

{HK={isp={Airtel=AirtelChennal}, www.enemalta.com={default=defaultEma, user1=chennal1}, studiodefault=hkDefaultchennal, country={DK=denmarkChennal, NO=chennal2}}}
like image 890
Vasantha Raj Avatar asked Jun 19 '15 13:06

Vasantha Raj


1 Answers

According to this article: http://makandracards.com/makandra/24809-yaml-keys-like-yes-or-no-evaluate-to-true-and-false

In order to use the strings ‘yes’ and ‘no’ as keys, you need to wrap them with quotes

like image 168
JP Moresmau Avatar answered Oct 26 '22 12:10

JP Moresmau