Tomasz Dziurko Tomasz Dziurko - 10 months ago 158
YAML Question

Mapping list in Yaml to list of objects in Spring Boot

In my Spring Boot app I have application.yaml configuration file with following content. I want to have it injected as a Configuration object with list of channel configurations:

xyz: "123"
name: "Company X"
companyBankAccount: "1000200030004000"
name: "Company Y"
companyBankAccount: "1000200030004000"

And @Configuration object I want to be populated with list of PaymentConfiguration objects:

@ConfigurationProperties(prefix = "available-payment-channels-list")
public class AvailableChannelsConfiguration {

private String xyz;

private List<ChannelConfiguration> channelConfigurations;

public AvailableChannelsConfiguration(String xyz, List<ChannelConfiguration> channelConfigurations) { = xyz;
this.channelConfigurations = channelConfigurations;

public AvailableChannelsConfiguration() {


// getters, setters

@ConfigurationProperties(prefix = "available-payment-channels-list.channelConfigurations")
public static class ChannelConfiguration {
private String name;
private String companyBankAccount;

public ChannelConfiguration(String name, String companyBankAccount) { = name;
this.companyBankAccount = companyBankAccount;

public ChannelConfiguration() {

// getters, setters


I am injecting this as a normal bean with @Autowired constructor. Value of xyz is populated correctly, but when Spring tries to parse yaml into list of objects I am getting

nested exception is java.lang.IllegalStateException:
Cannot convert value of type [java.lang.String] to required type
for property 'channelConfigurations[0]': no matching editors or
conversion strategy found]

Any clues what is wrong here?

Answer Source

The reason must be somewhere else. Using only Spring Boot 1.2.2 out of the box with no configuration, it Just Works. Have a look at this repo - can you get it to break?

Are you sure the YAML file looks exactly the way you pasted? No extra whitespace, characters, special characters, mis-indentation or something of that sort? Is it possible you have another file elsewhere in the search path that is used instead of the one you're expecting?