You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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()
}
}
}
The text was updated successfully, but these errors were encountered:
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:
The text was updated successfully, but these errors were encountered: