Skip to content

[REQ][JAVA]: Include @JsonProperty to fields in java model class when @lombok.Data is used with Jackson (serializationLibrary) #19743

@vishnuloga

Description

@vishnuloga

Description

Hi Team, Thanks for the great contribution of openapi-generator, This project helped me to generate a spring boot application automatically from openapi-spec with in few seconds (instead of manual work which takes minimum 1 or 2 days.)

  1. When I use the @lombok.Data in additionalModelTypeAnnotations with jackson serializationLibrary, the @JsonProperty annotation is missing in the generated java pojo model (because its included in the setter method of pojo only)
  2. In my use case I'm using Snake case for schema definition in my openapi spec
    Eg: field name
    in openapi spec: pet_purchased_date
    in java pojo class: petPurchasedDate
  3. It is causing issue when the input is converted to model in java

config:
openApiGenerate {
generatorName = "spring"
inputSpec = "$rootDir/openapi.yaml".toString()
outputDir = "$buildDir/openapi".toString()
apiPackage = "org.petstore.rest"
modelPackage = "org.petstore.interfaces"
apiFilesConstrainedTo = [""]
modelFilesConstrainedTo = [""]
configOptions = [useSpringBoot3: "true", serializationLibrary: "jackson", hideGenerationTimestamp: "true", additionalModelTypeAnnotations: "@lombok.Data; @lombok.AllArgsConstructor; @lombok.NoArgsConstructor;"]
skipValidateSpec = true
globalProperties = [skipFormModel: "false"]
importMappings = [Problem:"org.zalando.problem.Problem", Data:"lombok.Data", NoArgsConstructor:"lombok.NoArgsConstructor", AllArgsConstructor:"lombok.AllArgsConstructor"]
}

Solution

Include the below line as mentioned as per below image in the pojo.mustache
{{#lombok.Data}}{{#jackson}}@JsonProperty("{{baseName}}"){{/jackson}}{{/lombok.Data}}

image

pojo.mustache.json

Thanks
Vishnu

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