@Configuration
public class ConverterConfig {
@Bean
public Converter<String, LocalDate> localDateConverter() {
return source -> LocalDate.parse(source, CommonConstants.DATE_FORMATTER);
// return new Converter<String, LocalDate>() {
// @Override
// public LocalDate convert(String source) {
// return LocalDate.parse(source, CommonConstants.DATE_FORMATTER);
// }
// };
}
}
start app successfully when add converter without the lambda exp.otherwise,failed to start app and the following result will be outputted. Can't spring boot infer the type from the lambda exp?
Caused by: java.lang.IllegalArgumentException: Unable to determine source type <S> and target type <T> for your Converter [org.hoysing.stress.converter.ConverterConfig$$Lambda$1601/1414642952]; does the class parameterize those types?
Comment From: Hoysing
the version is 2.2.5
Comment From: philwebb
We need to update ApplicationConversionService.addBeans
to consider the factory method signature. We have some logic in ConfigurationPropertiesBean
that could probably be extracted.
Comment From: philwebb
Flagging for team attention to consider if we want to try and fix this as a bug, or consider it a known limitation and mark it as an enhancement.
Comment From: Hoysing
ok.thanks!
Comment From: snicoll
@philwebb don't we already have a PR about that? https://github.com/spring-projects/spring-boot/pull/22885
Comment From: philwebb
Thanks @snicoll, I knew I'd seen this issue before but I couldn't find it. Closing as a duplicate of #22885