Fix #23933: Added @JsonPropertyOrder annotation to Spring Boot generator#23957
Fix #23933: Added @JsonPropertyOrder annotation to Spring Boot generator#23957thesauravpoddar wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
No issues found across 1598 files
Note: This PR contains a large number of files. cubic only reviews up to 100 files per PR, so some files may not have been reviewed. cubic prioritizes the most important files to review.
On a pro plan you can use ultrareview for larger PRs.
Re-trigger cubic
|
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 |
@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 |
If you don’t want that you have just reconfigure your JsonMapper Bean like it was before. See https://spring.io/blog/2025/10/07/introducing-jackson-3-support-in-spring I see no reason to set an annotation here, every project can decide and configure the jsonmapper how they want |
This annotation already exists for the JAX-RS service (see #3778), all this MR does is extend the same functionality (as requested in #23933). Also, having this annotation makes the functionality for Jackson 3 exactly as it worked by default in Jackson 2, why would that be a bad thing? I haven't tested if setting the "spring.jackson.use-jackson2-defaults" property reverts the weird alphabetical order, but manually configuring the Jackson mapper didn't do much. |
|
There’s no reason to change the code if the functionality already exists. It’s simply unnecessary to redevelop features that are already there. The code also needs to be maintained, etc. Why would redundancy make the situation any better? If you don’t want an alphabetical order but rather the order of your DTO class, you just need to set a flag to false, and that’s it. With Jackson 2, you had to set it to true if you wanted that. They simply changed the default; nothing about Jackson’s functionality changed. That’s the standard way to use Jackson—you configure the JsonMapper/ObjectMapper according to your needs. Hier are some good migration guides: with the default changes from spring boot 4 You can just revert the default changes and should work like before. Here are a small example for spring boot with some changes For your case this make the trick like in jackson 2
|

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 modelsfrom the class-level annotation. I addes proper import for@JsonPropertyOrder annotation.Updated the
POJO.mustachefor spring boot with@JsonPropertyOrder annotationand updated theAbstractJavaCodegenwith adding import statement of@JsonPropertyOrder annotationunder methodprocessOpts.And updated the
SpringCodegenclass in which i updated the methodpostProcessModelProperty.Then finally adding test code for this in 'SpringCodegenTest.java' class
cc @Zomzog @martin-mfg @cachescrubber @welshm
PR checklist
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.
Summary by cubic
Add
@JsonPropertyOrderto 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
JsonPropertyOrderimport mapping inAbstractJavaCodegen.pojo.mustacheto apply@JsonPropertyOrderand emitJSON_PROPERTY_*constants.SpringCodegento importJsonPropertyOrderfor non-enum models only.SpringCodegenTestand regenerated Spring sample models.Migration
Written for commit 465a7af. Summary will update on new commits.