spring-ai icon indicating copy to clipboard operation
spring-ai copied to clipboard

GH-5797: Add RESPECT_JSONPROPERTY_ORDER to JsonSchemaGenerator

Open suryateja-g13 opened this issue 7 months ago • 1 comments

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

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

Fixes #5797

suryateja-g13 avatar Apr 21 '26 13:04 suryateja-g13

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

redinside-dev avatar Apr 22 '26 05:04 redinside-dev