Jackson json provider linkedHashSet deserialization

We use the Spring Leisure Pattern and the jackson json provider to serialize / deserialize json. From my services, I send the associated HashSet back, which receives the conversion to the HashSet on the client side when I receive it. Because of this, I lose the order in which elements are inserted. Is this a standard jackson json provider implementation for Set? Is there any other way, so it can be deserialized for proper implementation? I feel that it will be difficult, but the materials will be highly appreciated by you guys.

thanks

+4
source share
2 answers

You can specify a specific class for Jackson to use with the @JsonDeserialize annotation. Just put:

@JsonDeserialize(as=LinkedHashSet.class)

In the property adjuster.

+21
source

It all depends on what you are asking for the type of result: if you request data for display on a LinkedHashSet , then the JSON Array maps to it. If you use an undefined type of type java.lang.Object (or java.util.Collection ), you will get an ArrayList for JSON arrays. Keep in mind that JSON is data, not objects (by default), so metadata for the Java types you use is not passed by default. There are ways to do this if you need it, but usually you just need to provide the expected type.

+1
source

Source: https://habr.com/ru/post/1497101/


All Articles