Use Jackson enum values in generated schemas#6646
Open
ChoMinGi wants to merge 1 commit into
Open
Conversation
Jackson serializes enums using their `@JsonValue` method or the `@JsonProperty` values on constants, but generated JSON schemas advertised the Java constant names. A model following the schema then produces values the deserializer rejects with InvalidFormatException. Enable FLATTENED_ENUMS_FROM_JSONVALUE and FLATTENED_ENUMS_FROM_JSONPROPERTY in the victools Jackson module of JsonSchemaGenerator, JsonSchemaUtils, and McpJsonSchemaGenerator so schema enum values match Jackson's serialized form. Both options only affect enums using those annotations; plain enums keep emitting their constant names. Fixes spring-projects#1985 Signed-off-by: Mingi Cho <81455273+ChoMinGi@users.noreply.github.com>
ChoMinGi
marked this pull request as ready for review
July 19, 2026 15:46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1985
Jackson uses the values declared by
@JsonValueor@JsonPropertywhen serializing and deserializing enums, but generated JSON schemas currently advertise the Java constant names. A model following such a schema can therefore produce a value thatBeanOutputConvertercannot deserialize.This change enables victools'
FLATTENED_ENUMS_FROM_JSONVALUEandFLATTENED_ENUMS_FROM_JSONPROPERTYoptions inJsonSchemaGenerator,JsonSchemaUtils, andMcpJsonSchemaGenerator. This keeps structured output, tool input, and MCP schemas consistent with Jackson's enum representation.The
@JsonPropertymapping applies when all constants are annotated. Plain enums keep their existing constant names. For the affected enums, the previous schema advertised values the default deserializer rejects, so enabling the options by default corrects broken behavior rather than changing a working setup. No public API or converter-selection behavior is changed.The option pair was originally suggested in the #1985 discussion; the general schema-generator customization hook raised in the same thread is left as a separate follow-up.
An upgrade note and regression tests are included.
Tests
JsonSchemaGeneratorTestsJsonSchemaGeneratorKotlinTests— victools resolves@JsonValuefrom methods, so Kotlin properties use the@get:site targetJsonSchemaUtilsTestsBeanOutputConverterTestMcpJsonSchemaGeneratorTests./mvnw -pl spring-ai-model,spring-ai-client-chat,mcp/mcp-annotations test