Skip to content
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

@ConfigurationPropertiesBinding converters that rely on initial CharSequence to String conversion no longer work #39051

Closed
yanivnahoum opened this issue Jan 7, 2024 · 3 comments
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@yanivnahoum
Copy link

After upgrading to Spring Boot 3.2, our configtree property that uses a String->CustomType converter no longer works, throwing the following; org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.springframework.boot.env.ConfigTreePropertySource$PropertyFileContent] to type [<custom-type-here>]. The converter is registered with @ConfigurationPropertiesBinding.
You can find an example with tests that reproduce the issue here, branch configtree-custom-converter.
When downgrading to Spring Boot 3.1.6 the tests pass.
Alternatively, changing the converter to Object->CustomType works too.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 7, 2024
@wilkinsona wilkinsona self-assigned this Jan 8, 2024
@wilkinsona
Copy link
Member

Thanks for the report, @yanivnahoum, and for the sample that reproduces the problem.

Alternatively, changing the converter to Object->CustomType works too

CharSequence -> CustomType works as well.

@wilkinsona wilkinsona added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 8, 2024
@wilkinsona wilkinsona added this to the 3.2.x milestone Jan 8, 2024
@wilkinsona
Copy link
Member

The difference in behavior is due to the changes made for #34631. We suspect it was a risky fix and, unfortunately, we've been proven correct.

In 3.1.x, the custom String -> CustomType converter was in an ApplicationConversionService instance. The application conversion service contains a CharSequenceToObjectConverter. As a result the PropertyFileContent (which is a CharSequence) becomes a String and the String -> CustomType conversion can then be performed.

In 3.2, the property binding converters are isolated in a FormattingConversionService. This means that the PropertyFileContent input cannot be converted as there's nothing within the service to do the CharSequence -> String conversion that the custom converter requires.

As noted above, the problem can be worked around by declaring the converter a CharSequence -> CustomType. This will work with both 3.1 and 3.2. A fix in Boot itself will be trickier as we don't want to revert #34631. I believe it would work if we added a CharSequenceToObjectConverter instance to the FormattingConversionService used for property binding converters but that's prevented at the moment by it being package-private.

@wilkinsona wilkinsona changed the title configtree Property Source no longer works with Custom Converters @ConfigurationPropertiesBinding converters that rely on initial CharSequence to String conversion no longer work Jan 8, 2024
@wilkinsona wilkinsona added the for: team-meeting An issue we'd like to discuss as a team to make progress label Jan 8, 2024
@wilkinsona wilkinsona removed their assignment Jan 8, 2024
@philwebb
Copy link
Member

We're discussed this today and think that the least bad option is to copy/paste CharSequenceToObjectConverter to the bind converter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

4 participants