Skip to content

fix: Add a type deserializer to allow for JSON cloning of a JsonSchema object - #3315

Merged
bnasslahsen merged 1 commit into
springdoc:mainfrom
Mattias-Sehlstedt:handle-JsonSchema-json-cloning-asymmetry
Sep 6, 2026
Merged

fix: Add a type deserializer to allow for JSON cloning of a JsonSchema object#3315
bnasslahsen merged 1 commit into
springdoc:mainfrom
Mattias-Sehlstedt:handle-JsonSchema-json-cloning-asymmetry

Conversation

@Mattias-Sehlstedt

Copy link
Copy Markdown
Contributor

Change 4700208 introduced logic that involved cloning a schema with schema = cloneViaJson(schema, schema.getClass(), parameterBuilder.getObjectMapperProvider().jsonMapper());. This logic will fail for an OAS 3.1 specification, since the JsonSchema from swagger-core is not symmetric with regard to the type(s) field when doing back and forth de/serialization. See serialization configuration.

This means that types: [integer] becomes type: integer, which then cannot be deserialized back into JsonSchema.

This PR adjusts for that issue by adding a JsonSchema Mixin that forwards the type field into types.

Fixes #3314

@Mattias-Sehlstedt

Copy link
Copy Markdown
Contributor Author

Could also potentially be handled by changing
schema = cloneViaJson(schema, schema.getClass(), parameterBuilder.getObjectMapperProvider().jsonMapper());
to
schema = cloneViaJson(schema, Schema.class, parameterBuilder.getObjectMapperProvider().jsonMapper());
given that we trust the type casting to not lose any necessary information. That is what is done for cloneViaJson for list items, and also seem to be the general pattern used within swagger-core as well.

@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the handle-JsonSchema-json-cloning-asymmetry branch from b83a431 to 59f9a99 Compare August 7, 2026 09:27
@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the handle-JsonSchema-json-cloning-asymmetry branch from 59f9a99 to c48a4d5 Compare August 11, 2026 18:53
@bnasslahsen
bnasslahsen merged commit 2bd2774 into springdoc:main Sep 6, 2026
1 check passed
bnasslahsen added a commit that referenced this pull request Sep 6, 2026
…tions

Tabs, the ASF header, an @author tag, java-first import order and explicit
static imports for the files introduced by PR #3315.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
bnasslahsen pushed a commit that referenced this pull request Sep 6, 2026
…a object

Backport of PR #3315 from the Spring Boot 4 line.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

SpringDocUtils logs Json Processing Exception occurred warning for every @Min-constrained Integer query parameter (regression since 3.1.0)

2 participants