Fix #23933: Added @JsonPropertyOrder annotation to Spring Boot generator
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:
(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./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit./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
JsonPropertyOrderimport mapping inAbstractJavaCodegen. - Updated Spring Boot
pojo.mustacheto apply@JsonPropertyOrderand emitJSON_PROPERTY_*constants. - Updated
SpringCodegento importJsonPropertyOrderfor non-enum models only. - Added tests in
SpringCodegenTestand regenerated Spring sample models.
- Added
-
Migration
- Regenerate Spring Boot code to pick up ordered serialization. No code changes required.
Written for commit 465a7af1400428a6b68b93b951011c34818b4e1b. Summary will update on new commits.
HI! @Zomzo can you please look at the pull request
thanks for the pr
please resolve the merge conflicts when you've time.
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)
@cubic-dev-ai ultrareview
@cubic-dev-ai ultrareview
@thesauravpoddar Ultrareview is only available on the Pro plan. Upgrade here to get access.
Can You please look at this PR whenever you get time.
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)
Hey can you please look at this
@wing328 can you please look at this