Correct names of isolated Json/ObjectMapper properties

Closes gh-48116
This commit is contained in:
Andy Wilkinson
2025-11-13 12:00:19 +00:00
parent 62a1dd6ed1
commit bb0437c0e1
14 changed files with 38 additions and 28 deletions
@@ -389,7 +389,7 @@ TIP: See javadoc:org.springframework.boot.actuate.autoconfigure.endpoint.web.Cor
When working with JSON, Jackson is used for serialization and deserialization.
By default, an isolated javadoc:tools.jackson.databind.json.JsonMapper[] is used.
This isolation means that it does not share the same configuration as the application's `JsonMapper` and it is not affected by `spring.jackson.*` properties.
To disable this behavior and configure Actuator to use the application's `JsonMapper`, set configprop:management.endpoints.jackson.isolated-object-mapper[] to `false`.
To disable this behavior and configure Actuator to use the application's `JsonMapper`, set configprop:management.endpoints.jackson.isolated-json-mapper[] to `false`.
Alternatively, you can define your own javadoc:org.springframework.boot.actuate.endpoint.jackson.EndpointJsonMapper[] bean that produces a `JsonMapper` that meets your needs.
Actuator will then use it for JSON processing.
@@ -40,7 +40,7 @@ import org.springframework.context.annotation.Bean;
public final class Jackson2EndpointAutoConfiguration {
@Bean
@ConditionalOnBooleanProperty(name = "management.endpoints.jackson.isolated-object-mapper", matchIfMissing = true)
@ConditionalOnBooleanProperty(name = "management.endpoints.jackson2.isolated-object-mapper", matchIfMissing = true)
org.springframework.boot.actuate.endpoint.jackson.EndpointJackson2ObjectMapper jackson2EndpointJsonMapper() {
ObjectMapper objectMapper = org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.json()
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,
@@ -37,7 +37,7 @@ import org.springframework.context.annotation.Bean;
public final class JacksonEndpointAutoConfiguration {
@Bean
@ConditionalOnBooleanProperty(name = "management.endpoints.jackson.isolated-object-mapper", matchIfMissing = true)
@ConditionalOnBooleanProperty(name = "management.endpoints.jackson.isolated-json-mapper", matchIfMissing = true)
EndpointJsonMapper endpointJsonMapper() {
JsonMapper jsonMapper = JsonMapper.builder()
.changeDefaultPropertyInclusion(
@@ -44,10 +44,20 @@
}
},
{
"name": "management.endpoints.jackson.isolated-object-mapper",
"name": "management.endpoints.jackson.isolated-json-mapper",
"type": "java.lang.Boolean",
"description": "Whether to use an isolated JsonMapper to serialize endpoint JSON.",
"defaultValue": true
},
{
"name": "management.endpoints.jackson2.isolated-object-mapper",
"type": "java.lang.Boolean",
"description": "Whether to use an isolated object mapper to serialize endpoint JSON.",
"defaultValue": true
"defaultValue": true,
"deprecation": {
"reason": "Jackson 3 is preferred.",
"since": "4.0.0"
}
},
{
"name": "management.endpoints.jmx.domain",
@@ -64,7 +64,7 @@ class Jackson2EndpointAutoConfigurationTests {
@Test
void endpointObjectMapperWhenPropertyFalse() {
this.runner.withPropertyValues("management.endpoints.jackson.isolated-object-mapper=false")
this.runner.withPropertyValues("management.endpoints.jackson2.isolated-object-mapper=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(org.springframework.boot.actuate.endpoint.jackson.EndpointJackson2ObjectMapper.class));
}
@@ -50,13 +50,13 @@ class JacksonEndpointAutoConfigurationTests {
@Test
void endpointJsonMapperWhenPropertyTrue() {
this.runner.withPropertyValues("management.endpoints.jackson.isolated-object-mapper=true")
this.runner.withPropertyValues("management.endpoints.jackson.isolated-json-mapper=true")
.run((context) -> assertThat(context).hasSingleBean(EndpointJsonMapper.class));
}
@Test
void endpointJsonMapperWhenPropertyFalse() {
this.runner.withPropertyValues("management.endpoints.jackson.isolated-object-mapper=false")
this.runner.withPropertyValues("management.endpoints.jackson.isolated-json-mapper=false")
.run((context) -> assertThat(context).doesNotHaveBean(EndpointJsonMapper.class));
}
@@ -30,5 +30,5 @@ management.endpoint.health.group.comp.show-details=always
management.endpoints.migrate-legacy-ids=true
management.endpoints.jackson.isolated-object-mapper=true
management.endpoints.jackson.isolated-json-mapper=true
spring.jackson.mapper.require-setters-for-getters=true
@@ -17,7 +17,7 @@
package smoketest.actuator;
import org.junit.jupiter.api.Test;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.resttestclient.TestRestTemplate;
@@ -31,16 +31,16 @@ import org.springframework.test.context.ContextConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration test for WebMVC actuator when using an isolated {@link ObjectMapper}.
* Integration test for WebMVC actuator when not using an isolated {@link JsonMapper}.
*
* @author Phillip Webb
*/
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
properties = { "management.endpoints.jackson.isolated-object-mapper=false",
properties = { "management.endpoints.jackson.isolated-json-mapper=false",
"spring.jackson.mapper.require-setters-for-getters=true" })
@ContextConfiguration(loader = ApplicationStartupSpringBootContextLoader.class)
@AutoConfigureTestRestTemplate
class SampleActuatorApplicationIsolatedObjectMapperFalseTests {
class SampleActuatorApplicationIsolatedJsonMapperFalseTests {
@Autowired
private TestRestTemplate testRestTemplate;
@@ -17,7 +17,7 @@
package smoketest.actuator;
import org.junit.jupiter.api.Test;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.resttestclient.TestRestTemplate;
@@ -31,16 +31,16 @@ import org.springframework.test.context.ContextConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration test for WebMVC actuator when using an isolated {@link ObjectMapper}.
* Integration test for WebMVC actuator when using an isolated {@link JsonMapper}.
*
* @author Phillip Webb
*/
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
properties = { "management.endpoints.jackson.isolated-object-mapper=true",
properties = { "management.endpoints.jackson.isolated-json-mapper=true",
"spring.jackson.mapper.require-setters-for-getters=true" })
@ContextConfiguration(loader = ApplicationStartupSpringBootContextLoader.class)
@AutoConfigureTestRestTemplate
class SampleActuatorApplicationIsolatedObjectMapperTrueTests {
class SampleActuatorApplicationIsolatedJsonMapperTrueTests {
@Autowired
private TestRestTemplate testRestTemplate;
@@ -1,3 +1,3 @@
management.endpoints.web.exposure.include=*
management.endpoints.jackson.isolated-object-mapper=true
management.endpoints.jackson.isolated-json-mapper=true
spring.jackson2.visibility.field=any
@@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@AutoConfigureTestRestTemplate
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
properties = "management.endpoints.jackson.isolated-object-mapper=false")
properties = "management.endpoints.jackson2.isolated-object-mapper=false")
@ContextConfiguration(loader = ApplicationStartupSpringBootContextLoader.class)
class JerseyActuatorIsolatedObjectMapperFalseTests {
@@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@AutoConfigureTestRestTemplate
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
properties = "management.endpoints.jackson.isolated-object-mapper=true")
properties = "management.endpoints.jackson.isolated-json-mapper=true")
@ContextConfiguration(loader = ApplicationStartupSpringBootContextLoader.class)
class JerseyActuatorIsolatedObjectMapperTrueTests {
@@ -17,7 +17,7 @@
package smoketest.webflux;
import org.junit.jupiter.api.Test;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -27,16 +27,16 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.web.reactive.server.WebTestClient;
/**
* Integration test for WebFlux actuator when using an isolated {@link ObjectMapper}.
* Integration test for WebFlux actuator when using an isolated {@link JsonMapper}.
*
* @author Phillip Webb
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "management.endpoints.jackson.isolated-object-mapper=false",
properties = { "management.endpoints.jackson.isolated-json-mapper=false",
"spring.jackson.mapper.require-setters-for-getters=true" })
@ContextConfiguration(loader = ApplicationStartupSpringBootContextLoader.class)
@AutoConfigureWebTestClient
class SampleWebFluxApplicationActuatorIsolatedObjectMapperFalseTests {
class SampleWebFluxApplicationActuatorIsolatedJsonMapperFalseTests {
@Autowired
private WebTestClient webClient;
@@ -19,7 +19,7 @@ package smoketest.webflux;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -32,16 +32,16 @@ import org.springframework.test.web.reactive.server.WebTestClient;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration test for WebFlux actuator when not using an isolated {@link ObjectMapper}.
* Integration test for WebFlux actuator when not using an isolated {@link JsonMapper}.
*
* @author Phillip Webb
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "management.endpoints.jackson.isolated-object-mapper=true",
properties = { "management.endpoints.jackson.isolated-json-mapper=true",
"spring.jackson.mapper.require-setters-for-getters=true" })
@ContextConfiguration(loader = ApplicationStartupSpringBootContextLoader.class)
@AutoConfigureWebTestClient
class SampleWebFluxApplicationActuatorIsolatedObjectMapperTrueTests {
class SampleWebFluxApplicationActuatorIsolatedJsonMapperTrueTests {
@Autowired
private WebTestClient webClient;