Skip to content

Custom simple value converter not used on read #1689

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
ghost opened this issue Dec 5, 2023 · 0 comments
Closed

Custom simple value converter not used on read #1689

ghost opened this issue Dec 5, 2023 · 0 comments
Assignees
Labels
type: regression A regression from a previous release

Comments

@ghost
Copy link

ghost commented Dec 5, 2023

Issue appears when upgrading from 3.1.4 to 3.2.0

Example application, run test to reproduce: https://github.com/stephan-joeres-olx/jdbc-enum-conversion-bug

When enums are saved as lowercase Strings in DB, then it was possible to map them to uppercase Enums using a reading converter. This does not work any longer in 3.2.0. MappingRelationalConverter prefers default String to Enum mapping over the custom converter. The custom reading converter is not being used and the mapping is not successful.

Reading from DB produces: java.lang.IllegalArgumentException: No enum constant MyEnum.first

Converters are registered as this:

@Configuration
class JdbcConfig : AbstractJdbcConfiguration() {
    override fun userConverters(): List<*> = listOf(
        MyEnum.MyEnumReadingConverter(),
        MyEnum.MyEnumWritingConverter()
    )
}

enum class MyEnum {
    FIRST,
    SECOND;

    @ReadingConverter
    class MyEnumReadingConverter : Converter<String, MyEnum> {
        override fun convert(source: String): MyEnum {
            return MyEnum.valueOf(source.uppercase())
        }
    }

    @WritingConverter
    class MyEnumWritingConverter : Converter<MyEnum, String> {
        override fun convert(source: MyEnum): String {
            return source.toString().lowercase()
        }
    }
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 5, 2023
@mp911de mp911de changed the title Custom Enum reading converter not being used Custom simple value converter not used on read Dec 5, 2023
@mp911de mp911de added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 5, 2023
@mp911de mp911de self-assigned this Dec 5, 2023
@mp911de mp911de added this to the 3.2.1 (2023.1.1) milestone Dec 5, 2023
mp911de added a commit that referenced this issue Dec 5, 2023
We now apply converters for simple value reads ensuring that e.g. Enum converters are applied.

Closes #1689
@mp911de mp911de closed this as completed in 6034be8 Dec 5, 2023
mp911de added a commit that referenced this issue Dec 6, 2023
We now apply converters for simple value reads ensuring that e.g. Enum converters are applied.

Closes #1689
mp911de added a commit that referenced this issue Dec 6, 2023
We now apply converters for simple value reads ensuring that e.g. Enum converters are applied.

Closes #1689
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

2 participants