Skip to content

fixes(spring) add JsonProperty on setter#22978

Open
antechrestos wants to merge 1 commit intoOpenAPITools:masterfrom
antechrestos:fixes/22757-add-jackson-property-on-setter
Open

fixes(spring) add JsonProperty on setter#22978
antechrestos wants to merge 1 commit intoOpenAPITools:masterfrom
antechrestos:fixes/22757-add-jackson-property-on-setter

Conversation

@antechrestos
Copy link
Contributor

@antechrestos antechrestos commented Feb 15, 2026

In order to fix #22757, I applied same logic used on java side by #9041

  • extract jacksonAnnotation partial template
  • extract xmlAccessorAnnotation partial template
  • apply jacksonAnnotation and xmlAccessorAnnotation partial templates on both getter and setter

Summary by cubic

Add @JsonProperty to generated setter methods in Java Spring models so Jackson maps JSON names correctly, especially for custom or non-standard field names. Regenerates Spring samples to reflect the change and resolve deserialization mismatches (fixes #22757).

  • Bug Fixes
    • JavaSpring pojo.mustache: add @JsonProperty on setters when using Jackson, excluding jackson-optional-nullable fields.
    • Regenerated Spring sample models to annotate setters (e.g., fields like "@type", "123-list", names with dashes/spaces).
    • Ensures consistent property name mapping and setter-based deserialization without affecting Optional/JsonNullable behavior.

Written for commit 81ab5b7. Summary will update on new commits.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1178 files

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.

* extract jacksonAnnotation partial template
* extract xmkAccessorAnnotation partial template
* apply jacksonAnnotation partial template on both getter and setter

Fixes OpenAPITools#22757
@antechrestos antechrestos force-pushed the fixes/22757-add-jackson-property-on-setter branch from 81ab5b7 to e397869 Compare February 15, 2026 13:41
@antechrestos
Copy link
Contributor Author

@cubic-dev-ai rerun a review

@cubic-dev-ai
Copy link
Contributor

cubic-dev-ai bot commented Feb 15, 2026

@cubic-dev-ai rerun a review

@antechrestos I have started the AI code review. It will take a few minutes to complete.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1335 files

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.

@antechrestos
Copy link
Contributor Author

antechrestos commented Feb 15, 2026

@wing328 here's the fix I was waiting to push after the merge of #22854

As suggested in the issue #22757 , I applied the fix that already is present on java side; also, I used partial so as not to repeat myself.

There are tons of modified files yet difference consist in thee

$ git diff HEAD~1  --name-only  | grep -v samples/
modules/openapi-generator/src/main/resources/JavaSpring/jackson_annotations.mustache
modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache
modules/openapi-generator/src/main/resources/JavaSpring/xmlAccessorAnnotation.mustache
diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/jackson_annotations.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/jackson_annotations.mustache
new file mode 100644
index 00000000000..0668f40785c
--- /dev/null
+++ b/modules/openapi-generator/src/main/resources/JavaSpring/jackson_annotations.mustache
@@ -0,0 +1,7 @@
+  @JsonProperty("{{baseName}}")
+{{#withXml}}
+  @JacksonXmlProperty(localName = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#isXmlAttribute}}, isAttribute = true{{/isXmlAttribute}}{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
+  {{#isContainer}}
+  @JacksonXmlElementWrapper({{#isXmlWrapped}}localName = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}", {{#xmlNamespace}}namespace = "{{.}}", {{/xmlNamespace}}{{/isXmlWrapped}}useWrapping = {{isXmlWrapped}})
+  {{/isContainer}}
+{{/withXml}}
diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache
index 82a0a6eb00c..8a93fb054f1 100644
--- a/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache
+++ b/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache
@@ -226,25 +226,10 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
   {{#swagger1AnnotationLibrary}}
   @ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}")
   {{/swagger1AnnotationLibrary}}
-  {{#jackson}}
-  @JsonProperty("{{baseName}}")
-  {{#withXml}}
-  @JacksonXmlProperty(localName = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#isXmlAttribute}}, isAttribute = true{{/isXmlAttribute}}{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
-    {{#isContainer}}
-  @JacksonXmlElementWrapper({{#isXmlWrapped}}localName = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}", {{#xmlNamespace}}namespace = "{{.}}", {{/xmlNamespace}}{{/isXmlWrapped}}useWrapping = {{isXmlWrapped}})
-    {{/isContainer}}
-  {{/withXml}}
-  {{/jackson}}
-  {{#withXml}}
-  @Xml{{#isXmlAttribute}}Attribute{{/isXmlAttribute}}{{^isXmlAttribute}}Element{{/isXmlAttribute}}(name = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
-    {{#isXmlWrapped}}
-  @XmlElementWrapper(name = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}"{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
-    {{/isXmlWrapped}}
-  {{/withXml}}
   {{#deprecated}}
   @Deprecated
   {{/deprecated}}
-  public {{>nullableAnnotation}}{{>nullableDataTypeBeanValidation}} {{getter}}() {
+{{#jackson}}{{>jackson_annotations}}{{/jackson}}{{#withXml}}{{>xmlAccessorAnnotation}}{{/withXml}}  public {{>nullableAnnotation}}{{>nullableDataTypeBeanValidation}} {{getter}}() {
     return {{name}};
   }
   {{/lombok.Getter}}
@@ -261,7 +246,7 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
   {{#deprecated}}
   @Deprecated
   {{/deprecated}}
-  public void {{setter}}({{>nullableAnnotation}}{{>nullableDataType}} {{name}}) {
+{{#jackson}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{>jackson_annotations}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{/jackson}}  public void {{setter}}({{>nullableAnnotation}}{{>nullableDataType}} {{name}}) {
     this.{{name}} = {{name}};
   }
   {{/lombok.Setter}}
diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/xmlAccessorAnnotation.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/xmlAccessorAnnotation.mustache
new file mode 100644
index 00000000000..ee5195c0eb5
--- /dev/null
+++ b/modules/openapi-generator/src/main/resources/JavaSpring/xmlAccessorAnnotation.mustache
@@ -0,0 +1,4 @@
+  @Xml{{#isXmlAttribute}}Attribute{{/isXmlAttribute}}{{^isXmlAttribute}}Element{{/isXmlAttribute}}(name = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
+{{#isXmlWrapped}}
+  @XmlElementWrapper(name = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}"{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
+{{/isXmlWrapped}}

@wing328
Copy link
Member

wing328 commented Feb 15, 2026

Thanks for the PR

cc @cachescrubber (2022/02) @welshm (2022/02) @MelleD (2022/02) @atextor (2022/02) @manedev79 (2022/02) @javisst (2022/02) @borsch (2022/02) @banlevente (2022/02) @Zomzog (2022/09) @martin-mfg (2023/08)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [Java/Spring/Spring-Boot] @JsonProperty is missing on setters / deserialization problems using SpringBoot4 with field xRequestId

2 participants