Skip to content

Custom simple value converter not used on read #1689

Closed
@ghost

Description

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()
        }
    }
}

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions