Repository navigation
refactor: inject JsonMapper instead of ObjectMapper - #276
Open
adityamparikh wants to merge 1 commit into
Open
adityamparikh wants to merge 1 commit into
adityamparikh wants to merge 1 commit into
Conversation
Spring Boot 4's JacksonAutoConfiguration publishes format-specific mapper beans: JsonMapper always, plus XmlMapper and CBORMapper when jackson-dataformat-xml or jackson-dataformat-cbor is on the classpath. None is @primary and all extend ObjectMapper, so injecting ObjectMapper only resolves while JsonMapper is the sole candidate; adding either dataformat would fail startup with NoUniqueBeanDefinitionException. Every injection point and field here relies on JSON, so declare JsonMapper. Tests construct JsonMapper.builder().build() in place of new ObjectMapper(). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
|
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.



Spring Boot 4's
JacksonAutoConfigurationpublishes format-specific Jackson 3 mapper beans:JsonMapper jacksonJsonMapperXmlMapper xmlMapperjackson-dataformat-xmlis on the classpathCBORMapper cborMapperjackson-dataformat-cboris on the classpathNone of them is
@Primary, and all three extendObjectMapper. Our constructors currently ask forObjectMapper, which resolves only becauseJsonMapperis the sole candidate today. If either dataformat ever lands on the classpath, even transitively, every one of those injection points fails at startup withNoUniqueBeanDefinitionException.Every mapper in this codebase is used for JSON, so this declares
JsonMapper:CollectionService,SchemaService,JsonDocumentCreator,JsonResponseParserand theSolrConfig.jsonResponseParserbean method. Plus theSolrDocumentCreatorJavadoc example.@Autowired,@Mockand field types switch toJsonMapper, andnew ObjectMapper()becomesJsonMapper.builder().build(), matching the existing tests that already build mappers that way.Only types change; field and parameter names are unchanged.
JsonUtilsis left alone because #275 deletes it../gradlew buildpasses: 465 tests, 0 failures, 0 skipped.🤖 Generated with Claude Code