Fix #23933: Added @JsonPropertyOrder annotation to Spring Boot generator

TH
16d ago
+15743-0

This PR adds the @JsonPropertyOrder annotation to Spring Boot generator to fix the problem that Jackson 3 by default sorts properties alphabetically instead of following the logical order of the generated classes. It ensures that JSON properties are serialized in the logical order defined in the OpenAPI specification, while correctly excluding enum models from the class-level annotation. I addes proper import for @JsonPropertyOrder annotation.

Updated the POJO.mustache for spring boot with @JsonPropertyOrder annotation and updated the AbstractJavaCodegen with adding import statement of @JsonPropertyOrder annotation under method processOpts .

And updated the SpringCodegen class in which i updated the method postProcessModelProperty .
Then finally adding test code for this in 'SpringCodegenTest.java' class

cc @Zomzog @martin-mfg @cachescrubber @welshm

PR checklist

  • [x ] Read the contribution guidelines.
  • [ x] Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • [ 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.

Summary by cubic

Add @JsonPropertyOrder to generated Spring Boot models so JSON follows the OpenAPI field order instead of Jackson 3’s alphabetical sort. Enum models are excluded from the class-level annotation.

  • Bug Fixes

    • Added JsonPropertyOrder import mapping in AbstractJavaCodegen.
    • Updated Spring Boot pojo.mustache to apply @JsonPropertyOrder and emit JSON_PROPERTY_* constants.
    • Updated SpringCodegen to import JsonPropertyOrder for non-enum models only.
    • Added tests in SpringCodegenTest and regenerated Spring sample models.
  • Migration

    • Regenerate Spring Boot code to pick up ordered serialization. No code changes required.