question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG][JAVA] Deserialization of array with uniqueItems=true doesn't preserve order

See original GitHub issue

After 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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:20 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
borschcommented, Feb 3, 2022

@MelleD yep

1reaction
borschcommented, Feb 2, 2022

@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 for JsonNullable fields

https://github.com/OpenAPITools/openapi-generator/pull/11495

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found