Skip to content

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

@abrudin

Description

@abrudin

After #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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions