OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA] Deserialization of array with uniqueItems=true doesn't preserve order
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the generated Java model's setMyProp method, which currently accepts a Set and replaces the initialized LinkedHashSet during Jackson deserialization. Trace how uniqueItems=true produces this setter and verify the generated model's deserialized collection preserves input order; the issue provides no specific file or test path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100