0

So I have been trying to a list property from my YAML to a class that I made and somehow the list binding can only recognize comma-separated values from the YAML.

Given this class

@Getter
@Configuration
@ConfigurationProperties
@PropertySource("classpath:test.yml")
public class SomeProperty {
    final List<String> someList = new ArrayList<>();
}

And this yaml file

someList:
  - a
  - b

If I autowire the SomeProperty somewhere and print the someList, it will return an empty list, but if I change the yaml file to this

someList: a,b

Then the binding works and returns an array list containing the values. What is the problem with the binding?

ReiSchneider
  • 185
  • 1
  • 12
  • Does this answer your question? [How to bind yaml list to a java list in springboot?](https://stackoverflow.com/questions/37734469/how-to-bind-yaml-list-to-a-java-list-in-springboot) – pringi Feb 01 '22 at 09:45
  • @pringi No, that approach assumes that the yaml file I want to bind is the default application.yml. What I want to achieve is bind another external yaml file. Although I have discovered the problem, it is with PropertySource as it only recognizes property formats of key-value pairs – ReiSchneider Feb 01 '22 at 16:59
  • This has an example like you are trying to do: https://stackoverflow.com/questions/34063678/loading-multiple-yaml-files-using-configurationproperties – pringi Feb 01 '22 at 17:13
  • Yea, unfortunately, that approach has already been deprecated. Locations parameter for the ConfigurationProperties no longer exists – ReiSchneider Feb 02 '22 at 07:20

1 Answers1

0

Just found out that PropertySource can only recognize *.properties files that is why it cannot recognize yaml lists.

ReiSchneider
  • 185
  • 1
  • 12