Lessons learned about YAML and Norway

submited by
Style Pass
2022-09-23 17:30:25

YAML parsers usually do a good job in recognizing the correct types you are using. Parsing following YAML with for instance SnakeYAML will result in a Map containing the String “localhost” and the Integer 8080:

Here we’ll get a List with a String and an Integer. While this is great for this case it may be not great for all cases. A common pitfall is to unintentionally mix types:

Here we’ll get a List containing ten Integers and six Strings. Maybe not what we expected. While this example is quite obvious it may not always be so clear. I recently had problems with the list of Country-Codes defined in ISO-3166:

All of the entries are just two alphabetic characters so what could go wrong? It turns out that the Country-Code for Norway ‘NO’ is a boolean value for YAML.

Leave a Comment