How to define a map in a YAML file for simple POJO?

↘锁芯ラ 提交于 2019-12-31 17:48:29

问题


I am using snakeYaml to parse certain configuration/property values to a Configuration object.

My yaml file looks like this -

#Thread
batchLimit: 1000
threadCountLimit: 2

#Some More Config
key: value

#MAP
keyMapping: <What goes here?>

My Configuration class looks like this -

public class Configuration{
  int batchlimit;
  int threadCountLimit;
  ...
  Map<String,String> keyMapping;
}

How do I define the keyMapping in the YAML file so it reads directly through SnakeYAML?


回答1:


Here is how it can look like:

#MAP
keyMapping: 
    key1: value1
    key2: value2

Generally YAML format has natural support of key-value pairs. Take a look on the following tutorial (just for example): https://github.com/Animosity/CraftIRC/wiki/Complete-idiot's-introduction-to-yaml

Or just google "yaml map" for more details.



来源:https://stackoverflow.com/questions/34328749/how-to-define-a-map-in-a-yaml-file-for-simple-pojo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!