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

Incorrect serialization of enum map key #943

Closed
bimargulies opened this issue Sep 24, 2015 · 6 comments
Closed

Incorrect serialization of enum map key #943

bimargulies opened this issue Sep 24, 2015 · 6 comments
Milestone

Comments

@bimargulies
Copy link

https://github.com/bimargulies/jackson-enum-tc

I have a module with a key serializer for the enum class TestEnum. When I serialize from a map to a tree, where one of the map values it a map with a key of this enum type, the key serializer is not called.

@cowtowncoder
Copy link
Member

Does it only fail as part of regular Map? That is, works when serializing enum itself?

@bimargulies
Copy link
Author

Yea, it works for all kinds of other cases with that enum. The nested map is the first failure I've seen.

@cowtowncoder
Copy link
Member

Ok, that makes some sense, wrt finding the root cause. Assume this is with 2.6.2.

@cowtowncoder
Copy link
Member

After tackling other issues (such as much simpler #749), I hope to solve the issue of custom key serializer for "untyped" Maps (ones where key type is loose, usually java.lang.Object), which most commonly manifests itself as problem for root Map values. But it can also occur for other kinds of heterogenous Maps.

@cowtowncoder
Copy link
Member

FWTW, the useful caching-helper class is PropertySerializerMap, and given that key serializers are still instances of JsonSerializer, it should actually work as is. The main question will just be how to integrate the thing, wrt lookups. It may be easiest to hide this within new general-purpose key serializer instead of further complicating, say, MapSerializer. I hope to tackle this issue tomorrow.

@cowtowncoder
Copy link
Member

Was able to implement a dynamic key serializer based on ideas bounced on dev list. Key serializer is used if nominal type is detected as Object.class; assumption (for now) being that if a more specific type is passed, there is a reason for that. That part of the logic may be improved later on if and as needed.
For now local caching (within serializer) is done using PropertySerializerMap, but I also created an issue for possible adding a higher-level caching, similar to existing value serializer caches. This would help with the cases where Maps exist where number of distinct types for keys is large, and where PropertySerializerMap does not perform well (it is designed for lowish number of choices).

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