Skip to content

Conversation

@yangfeng123456
Copy link

Fixes an issue where the presence of a non-JSON ObjectMapper (such as CsvMapper)
prevents the auto-configuration of the default JsonMapper.

Previously, any ObjectMapper bean caused JsonMapper auto-configuration to back off,
which could lead to unexpected JSON serialization failures in web applications.

This change ensures that JsonMapper is still auto-configured when non-JSON
ObjectMapper beans are present.

A test has been added to verify the correct behavior.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 22, 2026
@yangfeng123456 yangfeng123456 force-pushed the fix-jsonmapper-csvmapper branch from 1c87998 to cd5cad2 Compare January 22, 2026 09:11
@wilkinsona
Copy link
Member

This appears to be a duplicate of #47379 and we already have a test for this:

@EnumSource
@ParameterizedTest
void mapperDoesNotBackOffWhenObjectMapperIsDefined(MapperType mapperType) {
this.contextRunner.withBean(ObjectMapper.class).run((context) -> {
assertThat(context).hasSingleBean(mapperType.mapperClass);
assertThat(context.getBeansOfType(ObjectMapper.class)).hasSize(MapperType.values().length + 1);
});
}

Furthermore, the proposed fix won't result in a change in behavior as the condition uses the method's return type by default. The test is also faulty as it asserts that there's a single ObjectMapper bean. There will be and should be multiple.

@wilkinsona wilkinsona closed this Jan 22, 2026
@wilkinsona wilkinsona added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 22, 2026
@yangfeng123456
Copy link
Author

This appears to be a duplicate of #47379 and we already have a test for this:

@EnumSource
@ParameterizedTest
void mapperDoesNotBackOffWhenObjectMapperIsDefined(MapperType mapperType) {
this.contextRunner.withBean(ObjectMapper.class).run((context) -> {
assertThat(context).hasSingleBean(mapperType.mapperClass);
assertThat(context.getBeansOfType(ObjectMapper.class)).hasSize(MapperType.values().length + 1);
});
}

Furthermore, the proposed fix won't result in a change in behavior as the condition uses the method's return type by default. The test is also faulty as it asserts that there's a single ObjectMapper bean. There will be and should be multiple.

Thank you very much for the detailed explanation and for taking the time to review this.

@wilkinsona
Copy link
Member

No problem, but please be more considerate of our time in future. Opening a PR that includes a test that doesn't pass isn't a good use of our time or yours. You should run the build locally and make sure that everything's working before submitting something for review.

@yangfeng123456
Copy link
Author

No problem, but please be more considerate of our time in future. Opening a PR that includes a test that doesn't pass isn't a good use of our time or yours. You should run the build locally and make sure that everything's working before submitting something for review.

Apologies for the oversight, and thank you for the feedback.

@yangfeng123456 yangfeng123456 deleted the fix-jsonmapper-csvmapper branch January 27, 2026 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: declined A suggestion or change that we don't feel we should currently apply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants