OpenAPITools / OpenAPITools/openapi-generator

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

Open
#10,167 20 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.