FasterXML / FasterXML/jackson-databind
Provide comparator for TreeMap deserialisation
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 1.5k
- Avg merge
- 3d 6h
- Merged PRs (30d)
- 28
Description
*Issue replaces https://github.com/FasterXML/jackson-core/issues/489, as the issue actually belonged here*
Both `SortedMap` and `TreeMap` can be deserialised, but by default use no special comparator is provided (i.e. natural order is used). This is because the default constructor is called for instantiating the `TreeMa`p. Now you could write special deserializers or subclass `TreeMap` and provide the comparator there, but that seems to be a pretty heavy change for something as easy as providing a constructor parameter for the value instantiator. Am I overseeing a certain way of how this can be achieved? And if not, could we consider introducing new annotations that allow users to specify which comparator to use for instantiated SortedSets, SortedMaps, etc?
Based on my stackoverflow question: https://stackoverflow.com/questions/48151413/deserialize-a-sortedset-with-a-provided-comparator
Original response from @cowtowncoder
> At the moment I don't think there is a way to achieve that for types that are not `Comparable` naturally (like `String`s).
>
> I am not sure what'd be the best way; while allowing annotations is a possibility this seems like niche case whereas ideally I think annotations would have wider applicability. So perhaps another configuration mechanism should be used. 2.10 introduces bit more flexible construction method for `ObjectMapper`s.
> That would give mechanism for global registration.
>
> But regardless, ability to configure this does sound like a good idea.
>
> One minor thing: this actually belongs to `jackson-databind` (`jackson-core` only covers streaming parser/generator, not databinding). Could you re-create it there please? (I don't know of github functionality that allows me to do that unfortunately).
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.