openapi-generator: [BUG][JAVA] Deserialization of array with uniqueItems=true doesn't preserve order
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
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 20 (20 by maintainers)
Commits related to this issue
- This is a workaround for the bug https://github.com/OpenAPITools/openapi-generator/issues/10167. When using Jackson, arrays with uniqueItems=true gets deserialized to HashSet rather than LinkedHashSet... — committed to candlepin/candlepin by deleted user 3 years ago
- This is a workaround for the issue https://github.com/OpenAPITools/openapi-generator/issues/10167. When using Jackson, arrays with uniqueItems=true gets deserialized to HashSet rather than LinkedHashS... — committed to candlepin/candlepin by deleted user 3 years ago
- This is a workaround for the issue https://github.com/OpenAPITools/openapi-generator/issues/10167. When using Jackson, arrays with uniqueItems=true gets deserialized to HashSet rather than LinkedHashS... — committed to candlepin/candlepin by deleted user 3 years ago
@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@JsonDeserializerforJsonNullablefieldshttps://github.com/OpenAPITools/openapi-generator/pull/11495