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
Describe the bug
It's not possible to use a custom Codec for an enum. The problem is that the built-in converters are checked first. There's a line in Conversions.java where it converts an enum to a string, bypassing the codecs.
It includes a custom codec factory and a custom codec for an enum. The factory prints when it's called, so it's easy to see that the factory isn't called for the needed codec.
Please complete the following information:
Server Version:
Driver Version:
Morphia Version: 2.3.0
Additional Info
I was able to work around this issue by creating a custom Converter for my enum. So this is not blocking me, but it does seem weird and surprising.
My goal in creating the custom enum codec is to handle invalid values better (defaulting to e.g. INVALID instead of throwing an exception). If the stock converter is important for performance reasons, I'd be happy with any solution that lets me handle invalid enum values.
The text was updated successfully, but these errors were encountered:
enums have long been a problem because it seems the driver's codec usually gets in the way. I thought I had this fixed way back but it seems there's a bit more work to do.
Describe the bug
It's not possible to use a custom Codec for an enum. The problem is that the built-in converters are checked first. There's a line in
Conversions.java
where it converts an enum to a string, bypassing the codecs.To Reproduce
I've created a reproducer here: https://github.com/eheimburg/enumserializedbug
It includes a custom codec factory and a custom codec for an enum. The factory prints when it's called, so it's easy to see that the factory isn't called for the needed codec.
Please complete the following information:
Additional Info
I was able to work around this issue by creating a custom Converter for my enum. So this is not blocking me, but it does seem weird and surprising.
My goal in creating the custom enum codec is to handle invalid values better (defaulting to e.g.
INVALID
instead of throwing an exception). If the stock converter is important for performance reasons, I'd be happy with any solution that lets me handle invalid enum values.The text was updated successfully, but these errors were encountered: