A way to use custom string values to map enums?
See original GitHub issueI have an enum like this:
public enum MyEnum {
DESCRIPTIVE_NAME1("short_code1"),
DESCRIPTIVE_NAME2("short_code2"),
...
MyEnum(String shortCode) {
this.shortCode = shortCode;
}
...
public static MyEnum fromShortCode(String shortCode) {
// lookup from MyEnum.values() using shortCode
}
}
And a class with MyEnum
field. The corresponding table column holds shortCode
values. Is there a way to use MyEnum.fromShortCode()
when reading the value from the result set? Right now anything I do doesn’t seem to have an effect and org.simpleflatmapper.converter.impl.CharSequenceToEnumConverter.convert()
gets called no matter what. This of course calls java.lang.Enum.valueOf()
and mapping fails.
I use SFM with JdbcTemplate and tried using both JdbcTemplateMapperFactory.addColumnDefinition()
and the ServiceLoader/Converter approach.
Any working example on how to achieve this? I imagine this is a fairly common use case, since other libraries like Jackson provide a special way to serialize/deserialize enums not only by their name.
Issue Analytics
- State:
- Created 5 years ago
- Comments:16 (11 by maintainers)
Top GitHub Comments
6.6.0 is being release at the minute and should work fine now with springboot devtools.
@neVERberleRfellerER created issue 623 to see if we can support the dev tools reload