FasterXML / FasterXML/jackson-databind

Provide comparator for TreeMap deserialisation

Đang mở
#2,162 9 bình luận 5 reaction 0 người được giao Xem trên GitHub
most-wanted
Ngôn ngữ chính
Java
Star
3.7k
Fork
1.5k
Merge trung bình
3 ngày 6 giờ
Pull request đã merge (30 ngày)
28

Mô tả

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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.