FasterXML / FasterXML/jackson-databind

Provide comparator for TreeMap deserialisation

Abierto
#2,162 9 comentarios 5 reacciones 0 asignados Ver en GitHub
most-wanted
Lenguaje dominante
Java
Estrellas
3.7k
Forks
1.5k
Merge medio
3 d 6 h
PR fusionados (30 d)
28

Descripción

*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).

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.