Bind YAML properties to Map<String, List<String>> type with Spring Boot

11,597

try to add this:

private Map<String, List<String>> keysList;

and put this in your .yml file

keysList:
    key1: 
        - value1
        - value2  
    key2: 
        - value2
        - value3
    key3: 
        - value3
        - value4

The result should be List mapping:

keysList={key1=[value1, value2], key2=[value2, value3], key3=[value3, value4]}

If you use on this way

private Map keysList;

you will get Map mapping.

keysList={key1={0=value1, 1=value2}, key2={0=value2, 1=value3}, key3={0=value3, 1=value4}}

Share:
11,597
salvador
Author by

salvador

Updated on June 12, 2022

Comments

  • salvador
    salvador almost 2 years

    I know that if I put the properties in the .yml file like that:

    list
      - item 1
      - item 2
    

    I can bind them to a java.util.List or Set type. Also If yaml properties are like that:

    map:
      key1: value1
      key2: value2
    

    I can bind thet to a Map. I wonder though if it is possible to bind yml properties to a Map<String, List<String>> type..