Skip to content
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

class cast exception for a key serializer for an enum type #601

Closed
benson-basis opened this issue Nov 5, 2014 · 5 comments
Closed

class cast exception for a key serializer for an enum type #601

benson-basis opened this issue Nov 5, 2014 · 5 comments

Comments

@benson-basis
Copy link
Contributor

See https://github.com/benson-basis/jackson-enum-key-ser-tc with Jackson 2.4.3.

boom(org.fasterxml.tc.EnumKeyBoomTest)  Time elapsed: 0.228 sec  <<< ERROR!
com.fasterxml.jackson.databind.JsonMappingException: org.fasterxml.tc.TestEnumSerializer cannot be cast to com.fasterxml.jackson.databind.ser.std.StdSerializer
        at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:125)
        at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:2866)
        at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:2323)
        at org.fasterxml.tc.EnumKeyBoomTest.boom(EnumKeyBoomTest.java:39)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
@benson-basis
Copy link
Contributor Author

The problem here is that enum maps can't tolerate custom serializers on their key enums.

@cowtowncoder
Copy link
Member

I think one part of the solution could be to revert to using standard Map serializer in this case, as it should handle keys of various types, and leave EnumMapSerializer for "simple" cases.

@benson-basis
Copy link
Contributor Author

Is that something you do or I do? :-)

@cowtowncoder
Copy link
Member

I'll try to figure out. Thank you for reporting this!

@cowtowncoder
Copy link
Member

Hmmh. Handling is quite messy. I may have to fix this in 2.5, to pass more information for EnumMapSerializer constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants