Skip to content

[Java] add jackson annotations to setters#9041

Merged
wing328 merged 2 commits intoOpenAPITools:masterfrom
SoMuchForSubtlety:master
Mar 30, 2021
Merged

[Java] add jackson annotations to setters#9041
wing328 merged 2 commits intoOpenAPITools:masterfrom
SoMuchForSubtlety:master

Conversation

@SoMuchForSubtlety
Copy link
Contributor

@SoMuchForSubtlety SoMuchForSubtlety commented Mar 22, 2021

Closes #6856

Jackson deserialization fails with the message "Problem deserializing 'setterless' property" if json keys are not in camel case. This commit fixes that problem by adding @JsonProprety to setters.

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
  • File the PR against the correct branch: master
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @nmuesch

@SoMuchForSubtlety
Copy link
Contributor Author

Looks like this creates an issue when JsonNullable is also used:

  @JsonProperty(JSON_PROPERTY_NULLABLE_SHAPE)
  public void setNullableShape_JsonNullable(JsonNullable<NullableShape> nullableShape) {
    this.nullableShape = nullableShape;
  }

  @JsonProperty(JSON_PROPERTY_NULLABLE_SHAPE)
  @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
  public void setNullableShape(NullableShape nullableShape) {
    this.nullableShape = JsonNullable.<NullableShape>of(nullableShape);
  }
com.fasterxml.jackson.databind.JsonMappingException: 
Conflicting setter definitions for property "nullableShape": org.openapitools.client.model.Drawing#setNullableShape(1 params) vs org.openapitools.client.model.Drawing#setNullableShape_JsonNullable(1 params)

two possible solutions are:

  • add jackson annotations to fields instead of methods
  • only add jackson annotations to the regular setter if there is no JsonNullable setter

@SoMuchForSubtlety
Copy link
Contributor Author

I implemented option two.

@SoMuchForSubtlety
Copy link
Contributor Author

@wing328 any chance of getting this into the next minor release?

Copy link
Member

@wing328 wing328 left a comment

Choose a reason for hiding this comment

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

LGTM but I've not tested it locally

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.

No @JsonProperty on setters of generated java model

2 participants