Skip to content

[Java] deserialize to LinkedHashSet when unique items#10241

Merged
wing328 merged 7 commits intoOpenAPITools:masterfrom
borsch:deserialize-to-linkedhashset
Nov 14, 2021
Merged

[Java] deserialize to LinkedHashSet when unique items#10241
wing328 merged 7 commits intoOpenAPITools:masterfrom
borsch:deserialize-to-linkedhashset

Conversation

@borsch
Copy link
Copy Markdown
Member

@borsch borsch commented Aug 24, 2021

fix issue: #10167

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@borsch
Copy link
Copy Markdown
Member Author

borsch commented Aug 26, 2021

@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @nmuesch (2021/01) @wing328

@wing328
Copy link
Copy Markdown
Member

wing328 commented Aug 31, 2021

CI reports the following failure. Can you please take a look when you've time?

[ERROR] COMPILATION ERROR : 
[ERROR] /home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/model/Pet.java:[210,40] error: incompatible types: Class<LinkedHashSet> cannot be converted to Class<? extends JsonDeserializer>
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project petstore-feign: Compilation failure
[ERROR] /home/circleci/OpenAPITools/openapi-generator/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/model/Pet.java:[210,40] error: incompatible types: Class<LinkedHashSet> cannot be converted to Class<? extends JsonDeserializer>
[ERROR] -> [Help 1]

Ref: https://app.circleci.com/pipelines/github/OpenAPITools/openapi-generator/12357/workflows/53530b0f-82c0-4a08-8a42-77cc4cf6b5bc/jobs/25986

@wing328
Copy link
Copy Markdown
Member

wing328 commented Aug 31, 2021

Here is another one:

[ERROR] COMPILATION ERROR : 
[ERROR] /home/circleci/OpenAPITools/openapi-generator/samples/server/petstore/jaxrs/jersey2/src/gen/java/org/openapitools/model/Pet.java:[184,41] incompatible types: java.lang.Class<java.util.LinkedHashSet> cannot be converted to java.lang.Class<? extends com.fasterxml.jackson.databind.JsonDeserializer>
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project jaxrs-jersey-petstore-server: Compilation failure
[ERROR] /home/circleci/OpenAPITools/openapi-generator/samples/server/petstore/jaxrs/jersey2/src/gen/java/org/openapitools/model/Pet.java:[184,41] incompatible types: java.lang.Class<java.util.LinkedHashSet> cannot be converted to java.lang.Class<? extends com.fasterxml.jackson.databind.JsonDeserializer>
[ERROR] -> [Help 1]

Ref: https://app.circleci.com/pipelines/github/OpenAPITools/openapi-generator/12357/workflows/53530b0f-82c0-4a08-8a42-77cc4cf6b5bc/jobs/25986/parallel-runs/1?filterBy=FAILED => then click on node 1

…rator into deserialize-to-linkedhashset

� Conflicts:
�	modules/openapi-generator/src/main/resources/JavaJaxRS/spec/pojo.mustache
�	samples/server/petstore/jaxrs-spec-interface/src/gen/java/org/openapitools/model/Pet.java
�	samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/Pet.java
@borsch
Copy link
Copy Markdown
Member Author

borsch commented Sep 23, 2021

@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @nmuesch (2021/01) @wing328

@borsch
Copy link
Copy Markdown
Member Author

borsch commented Sep 29, 2021

@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @nmuesch (2021/01) @wing328

} else if ("set".equals(property.containerType)) {
model.imports.add("LinkedHashSet");
model.imports.add("JsonDeserialize");
property.vendorExtensions.put("x-setter-extra-annotation", "@JsonDeserialize(as = LinkedHashSet.class)");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI. I may rename it to x-java-setter-extra-annotation later as this extension is for the Java generators only.

@wing328 wing328 added this to the 5.3.1 milestone Nov 14, 2021
@wing328 wing328 merged commit 3bdbf03 into OpenAPITools:master Nov 14, 2021
@MelleD
Copy link
Copy Markdown
Contributor

MelleD commented Jan 27, 2022

@borsch and @wing328
This PR broke the JsonNullable deserialization. If you use a JsonNullable with uniqueItems. This code will generated:

e.g.

@JsonDeserialize(as = LinkedHashSet.class)
public void setFoos(JsonNullable<Set<String>> foos) {
  this.foos = foos;
}

Exception

[.c.j.MappingJackson2HttpMessageConverter] : Failed to evaluate Jackson deserialization for type [[simple type, class FooDto]]: com.fasterxml.jackson.databind.JsonMappingException: Failed to narrow type [simple type, class org.openapitools.jackson.nullable.JsonNullable<java.util.Set<java.lang.String>>] with annotation (value java.util.LinkedHashSet), from 'setFoos': Class `java.util.LinkedHashSet` not subtype of `org.openapitools.jackson.nullable.JsonNullable<java.util.Set<java.lang.String>>`
foos:
  type: array
  uniqueItems: true
  items:
    type: string
  maxItems: 10
  nullable: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants