Skip to content

GH-5797: Add RESPECT_JSONPROPERTY_ORDER to JsonSchemaGenerator#5847

Open
suryateja-g13 wants to merge 1 commit intospring-projects:mainfrom
suryateja-g13:GH-5797
Open

GH-5797: Add RESPECT_JSONPROPERTY_ORDER to JsonSchemaGenerator#5847
suryateja-g13 wants to merge 1 commit intospring-projects:mainfrom
suryateja-g13:GH-5797

Conversation

@suryateja-g13
Copy link
Copy Markdown

Thank you for taking time to contribute this pull request!

Problem

BeanOutputConverter configures its JacksonSchemaModule with both JacksonOption.RESPECT_JSONPROPERTY_REQUIRED and JacksonOption.RESPECT_JSONPROPERTY_ORDER, but JsonSchemaGenerator only includes RESPECT_JSONPROPERTY_REQUIRED.

This inconsistency means @JsonPropertyOrder annotations are silently ignored when generating schemas through JsonSchemaGenerator (e.g. via ResponseFormat.jsonSchema(MyClass.class)), even though they work correctly via BeanOutputConverter.

Solution

Add the missing JacksonOption.RESPECT_JSONPROPERTY_ORDER option to the JacksonSchemaModule configuration in JsonSchemaGenerator, aligning it with BeanOutputConverter.

Changes

  • JsonSchemaGenerator.java — added JacksonOption.RESPECT_JSONPROPERTY_ORDER to JacksonSchemaModule constructor
  • JsonSchemaGeneratorTests.java — added generateSchemaForTypeRespectsJsonPropertyOrder test using an @JsonPropertyOrder-annotated class; verified the schema properties are emitted in the declared order

Checklist

  • Added Signed-off-by line to commit (DCO)
  • Rebased on latest main
  • Unit tests added
  • Build passes (mvn package -pl spring-ai-model)

Fixes #5797

…enerator

BeanOutputConverter already included JacksonOption.RESPECT_JSONPROPERTY_ORDER
in its JacksonSchemaModule configuration, but JsonSchemaGenerator did not.
This caused @JsonPropertyOrder annotations to be silently ignored when
generating schemas via ResponseFormat.jsonSchema() or any path that uses
JsonSchemaGenerator directly.

Add the missing option to keep both code paths consistent.

Fixes spring-projectsGH-5797 (spring-projects#5797)

Signed-off-by: Gorre Surya <sgorre92@gmail.com>
Copy link
Copy Markdown

@anuragg-saxenaa anuragg-saxenaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Single-line addition: adds RESPECT_JSONPROPERTY_ORDER to JsonSchemaGenerator schema module options, matching BeanOutputConverter config. Eliminates silent failure of @JsonPropertyOrder annotations. Clean fix, well-scoped.

@redinside-dev
Copy link
Copy Markdown

LGTM. Adds JacksonOption.RESPECT_JSONPROPERTY_ORDER to JacksonSchemaModule — focused and correct. Test verifies the ordering matches the annotation. Ship it.

Copy link
Copy Markdown

@redinside-dev redinside-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Tiny, targeted fix that aligns with by adding the missing option to the configuration. The test covers the annotation case thoroughly. Simple, correct, shipped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RESPECT_JSONPROPERTY_ORDER not enabled in JsonSchemaGenerator

3 participants