Skip to content

Converter beans cannot be defined as lambdas #24413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Hoysing opened this issue Dec 9, 2020 · 6 comments
Closed

Converter beans cannot be defined as lambdas #24413

Hoysing opened this issue Dec 9, 2020 · 6 comments
Labels
status: duplicate A duplicate of another issue

Comments

@Hoysing
Copy link

Hoysing commented Dec 9, 2020

@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?
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 9, 2020
@Hoysing
Copy link
Author

Hoysing commented Dec 9, 2020

the version is 2.2.5

@philwebb
Copy link
Member

philwebb commented Dec 9, 2020

We need to update ApplicationConversionService.addBeans to consider the factory method signature. We have some logic in ConfigurationPropertiesBean that could probably be extracted.

@philwebb philwebb added for: team-attention An issue we'd like other members of the team to review type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 9, 2020
@philwebb philwebb added this to the 2.2.x milestone Dec 9, 2020
@philwebb
Copy link
Member

philwebb commented Dec 9, 2020

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.

@Hoysing
Copy link
Author

Hoysing commented Dec 9, 2020

ok.thanks!

@philwebb philwebb changed the title Can't spring boot infer the type from the lambda exp? Converter beans cannot be defined as lambdas Dec 9, 2020
@snicoll
Copy link
Member

snicoll commented Dec 9, 2020

@philwebb don't we already have a PR about that? #22885

@philwebb
Copy link
Member

philwebb commented Dec 9, 2020

Thanks @snicoll, I knew I'd seen this issue before but I couldn't find it. Closing as a duplicate of #22885

@philwebb philwebb closed this as completed Dec 9, 2020
@philwebb philwebb added status: duplicate A duplicate of another issue and removed for: team-attention An issue we'd like other members of the team to review type: bug A general bug labels Dec 9, 2020
@philwebb philwebb removed this from the 2.2.x milestone Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

4 participants