Skip to content

fix: use the JSON type Jackson writes for scalar types in JSON schemas - #2155

Merged
octonato merged 2 commits into
mainfrom
fix-json-schema-string-types
Nov 3, 2026
Merged

octonato merged 2 commits into
mainfrom
fix-json-schema-string-types

Conversation

@johanandren

Copy link
Copy Markdown
Contributor

🤖 JSON schemas now use the JSON type that Jackson writes for scalar types. Before this change, the schema did not match the Jackson output for several types:

Field type Old schema Jackson output New schema
byte[] array of integers base64 string string
URI object with 17 required properties string string
BigInteger object requiring lowestSetBit number integer

URL, Date, ZoneId, Locale, Currency, YearMonth and similar types had the same problem. The wrong schemas reached agent tool inputs, MCP tool input and output schemas, and HTTP endpoint descriptions. An MCP client that checks structured content against the output schema rejected these values.

  • For a class that is not an Optional, collection, enum or protobuf message, the schema asks the Jackson format visitor for the JSON type. A string, number, integer or boolean gives a scalar schema. Any other type is introspected as an object, as before. A user class with @JsonValue or a class-level serializer also gets the scalar type.
  • Jackson reports byte[], char[] and ByteBuffer as arrays but writes them as strings, so these have their own case.
  • OptionalInt, OptionalLong and OptionalDouble give an integer or number schema and are not required.
  • An HTTP endpoint describes only a String body as a text/plain body. The runtime parses any other body as JSON. An Instant or UUID body was already described wrongly, and this change would have added more types.

The test serializes an example with the SDK mapper and checks each JSON value against the schema type.

Reported in the review of #2101.

@octonato
octonato merged commit 9fb97c0 into main Nov 3, 2026
34 checks passed
@octonato
octonato deleted the fix-json-schema-string-types branch November 3, 2026 14:24
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.

2 participants