Lista de mapeamento no Yaml para lista de objetos no Spring Boot
No meu aplicativo Spring Boot, tenho o arquivo de configuração application.yaml com o seguinte conteúdo. Quero que ele seja injetado como um objeto de configuração com uma lista de configurações de canal:
available-payment-channels-list:
xyz: "123"
channelConfigurations:
-
name: "Company X"
companyBankAccount: "1000200030004000"
-
name: "Company Y"
companyBankAccount: "1000200030004000"
E o objeto @Configuration que eu quero que seja preenchido com a lista de objetos PaymentConfiguration:
@ConfigurationProperties(prefix = "available-payment-channels-list")
@Configuration
@RefreshScope
public class AvailableChannelsConfiguration {
private String xyz;
private List<ChannelConfiguration> channelConfigurations;
public AvailableChannelsConfiguration(String xyz, List<ChannelConfiguration> channelConfigurations) {
this.xyz = xyz;
this.channelConfigurations = channelConfigurations;
}
public AvailableChannelsConfiguration() {
}
// getters, setters
@ConfigurationProperties(prefix = "available-payment-channels-list.channelConfigurations")
@Configuration
public static class ChannelConfiguration {
private String name;
private String companyBankAccount;
public ChannelConfiguration(String name, String companyBankAccount) {
this.name = name;
this.companyBankAccount = companyBankAccount;
}
public ChannelConfiguration() {
}
// getters, setters
}
}
Estou injetando isso como um bean normal com o construtor @Autowired. O valor de xyz é preenchido corretamente, mas quando o Spring tenta analisar o yaml na lista de objetos que estou recebendo
nested exception is java.lang.IllegalStateException:
Cannot convert value of type [java.lang.String] to required type
[io.example.AvailableChannelsConfiguration$ChannelConfiguration]
for property 'channelConfigurations[0]': no matching editors or
conversion strategy found]
Alguma pista do que está errado aqui?