[BUG][JAVA] Deserialization of array with uniqueItems=true doesn't preserve order
See original GitHub issueAfter https://github.com/OpenAPITools/openapi-generator/issues/5254 was fixed and merged, when using Jackson, arrays with uniqueItems=true gets deserialized to HashSet rather than LinkedHashSet, thus not preserving order as expected.
Even though the field (myProp) is initialized to an empty LinkedHashSet, it is promptly overwritten with a regular HashSet given that there is no deserialization-hint (@JsonDeserialize(as = LinkedHashSet.class)) on the setMyProp-method. The method invoked looks like this:
@JsonProperty(JSON_PROPERTY_MY_PROP)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public void setMyProp(Set<SomeEnum> myProp) {
this.myProp = myProp;
}
and thus there is no way for Jackson to understand that order needs to be preserved.
This issue is present in version 5.2.1
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:20 (20 by maintainers)
Top Results From Across the Web
java - deserialization of a json array to a list and retaining the ...
I have the following json that is mapped to a POJO using Jackson mapper. How do I retain the order of array columns...
Read more >Serialization and deserialization in Java | Snyk Blog
Explaining Java deserialize vulnerabilities. A serialized object in Java is a byte array with state information. It contains the name of the ...
Read more >Deserialization of untrusted data - OWASP Foundation
However, deserialized data or code can often be modified without using the provided accessor functions if it does not use cryptography to protect...
Read more >JDK-8154961 JEP 290: Filter Incoming Serialization Data
The filter interface methods are called during the deserialization process to validate the classes being deserialized, the sizes of arrays being created, ...
Read more >Gson — Mapping of Arrays and Lists of Objects - Future Studio
Getting Started with Java-JSON Serialization & Deserialization · Mapping of ... In the JSON data format, there are no lists or arrays.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@MelleD yep
@MelleD I spent some time googling possible solution how to keep both
JsonNullable
&LinkedHashSet
, but haven’t found anything yet. Here is a solution that I’ve mentioned before - skip@JsonDeserializer
forJsonNullable
fieldshttps://github.com/OpenAPITools/openapi-generator/pull/11495