Answer the question
In order to leave comments, you need to log in
Java, Jackson desirialization. How to handle generec type based on interface from java.util?
public class Bla
{
public SortedSet<Comparable> values;
}
public class ArraySortedSet<E extends Comparable<E>>
extends AbstractSet<E>
implements SortedSet<E>, Serializable
{
}
Answer the question
In order to leave comments, you need to log in
The problem is that you don't have type information basically because List.class doesn't have any information about Generic.
There are two ways to solve this problem:
1. Extend the ArrayList class, which will not work with generic
2. Use ObjectWriter (like mapper.writerForType(listType).writeValueAsString())
listType can be done through TypeFactory or TypeReference
It seems to be written in Russian in English letters ...
Comparable is an interface and it needs an implementation, otherwise Jackson will not be able to create an object for you (where will it put the fields from json?). Find (write) the implementation of this interface you need and use it in deserialization, something like this:
mapper.readValue(objectJson, mapper.getTypeFactory().constructCollectionType(SortedSet.class, <ВАША РЕАЛИЗАЦИЯ Comparable>))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question