Skip to content

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

@WennySoft

Description

@WennySoft

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

problem;
When generating modles with spring/spring-boot jacksons annotations @JsonProperty are put only on the getters. On deserializing jackson needs them at the setters to take place. Without them the default mapping is used.

Until SpringBoot 3 this worked for a property (not header) 'xRequestId' but with SpringBoot 4 the default behaviour changed and valid requests are not validated anymore as the xRequestId is left null after deserializing

suggested fix
add the JsonProperty annotations also on the setters. I did this by modifying the template pojo.mustache (from master) and this works

openapi-generator version

7.17.0 and 7.19.0

OpenAPI declaration file content or url
openapi: 3.1.0
info:
  title: dummy api
  description: Simple Spec to show problem
  version: 0.0.0
components:
  schemas:
    someObj:
      type: object
      required:
        - xRequestId
      properties:
        xRequestId:
          type: string
          example: "9f09113b-1f95-4c8a-b90a-c5bf6c35c4d9"
          format: uuid
Generation Details

Generated using maven

            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>7.19.0</version>
                <configuration>
                    <generatorName>spring</generatorName>
                    <library>spring-boot</library>
                    <configOptions>
                        <useSpringBoot3>true</useSpringBoot3>
                        <useJakartaEee>true</useJakartaEee>
                    </configOptions>
                    <inputSpec>simple-api.yml</inputSpec>
                </configuration>
                <executions>
                    <execution>
                        <id>generate-txdata</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

lead to

 /**
   * Get xRequestId
   * @return xRequestId
   */
  @NotNull @Valid 
  @Schema(name = "xRequestId", example = "9f09113b-1f95-4c8a-b90a-c5bf6c35c4d9", requiredMode = Schema.RequiredMode.REQUIRED)
  @JsonProperty("xRequestId")
  public UUID getxRequestId() {
    return xRequestId;
  }

  public void setxRequestId(UUID xRequestId) {
    this.xRequestId = xRequestId;
  }

note the missing @JsonProperty on setxRequestId

I assume that the default change is regarding 1 lower letter followed directly by 1 upper letter on property name

Steps to reproduce

Take the given api and generate the code with the plugin configuration above

Related issues/PRs

There seemed to be a fix in the past

Suggest a fix

Copy jackson config from getters to setters in https://github.com/OpenAPITools/openapi-generator/blob/342febde58e655953a697320f30dd1febdf09ef5/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache

Image

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