Revert Support pluggable types for EndpointJsonMapper

Closes gh-46534
This commit is contained in:
Phillip Webb
2025-10-09 22:48:45 -07:00
parent 02b2d03acf
commit e01b36216a
4 changed files with 10 additions and 57 deletions
@@ -16,9 +16,6 @@
package org.springframework.boot.actuate.autoconfigure.endpoint.jackson;
import java.util.HashSet;
import java.util.Set;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;
@@ -29,7 +26,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.util.ClassUtils;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Endpoint Jackson support.
@@ -40,8 +36,6 @@ import org.springframework.util.ClassUtils;
@AutoConfiguration
public final class JacksonEndpointAutoConfiguration {
private static final String CONTRIBUTED_HEALTH = "org.springframework.boot.health.contributor.ContributedHealth";
@Bean
@ConditionalOnBooleanProperty(name = "management.endpoints.jackson.isolated-object-mapper", matchIfMissing = true)
@ConditionalOnClass(ObjectMapper.class)
@@ -50,24 +44,7 @@ public final class JacksonEndpointAutoConfiguration {
.changeDefaultPropertyInclusion(
(value) -> value.withValueInclusion(Include.NON_NULL).withContentInclusion(Include.NON_NULL))
.build();
Set<Class<?>> supportedTypes = new HashSet<>(EndpointJsonMapper.DEFAULT_SUPPORTED_TYPES);
if (ClassUtils.isPresent(CONTRIBUTED_HEALTH, null)) {
supportedTypes.add(ClassUtils.resolveClassName(CONTRIBUTED_HEALTH, null));
}
return new EndpointJsonMapper() {
@Override
public JsonMapper get() {
return jsonMapper;
}
@Override
public Set<Class<?>> getSupportedTypes() {
return supportedTypes;
}
};
return () -> jsonMapper;
}
}
@@ -16,8 +16,6 @@
package org.springframework.boot.actuate.endpoint.jackson;
import java.util.Set;
import tools.jackson.databind.json.JsonMapper;
import org.springframework.boot.actuate.endpoint.OperationResponseBody;
@@ -30,13 +28,9 @@ import org.springframework.boot.actuate.endpoint.OperationResponseBody;
* @since 4.0.0
* @see OperationResponseBody
*/
@FunctionalInterface
public interface EndpointJsonMapper {
/**
* The default supported types.
*/
Set<Class<?>> DEFAULT_SUPPORTED_TYPES = Set.of(OperationResponseBody.class);
/**
* Return the {@link JsonMapper} that should be used to serialize
* {@link OperationResponseBody} endpoint results.
@@ -44,12 +38,4 @@ public interface EndpointJsonMapper {
*/
JsonMapper get();
/**
* Return the types that this endpoint mapper supports.
* @return the supported types
*/
default Set<Class<?>> getSupportedTypes() {
return DEFAULT_SUPPORTED_TYPES;
}
}
@@ -21,7 +21,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import tools.jackson.databind.json.JsonMapper;
@@ -68,7 +67,6 @@ import org.springframework.http.codec.HttpMessageWriter;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.http.codec.json.JacksonJsonEncoder;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.util.MimeType;
import org.springframework.util.StringUtils;
import org.springframework.util.function.SingletonSupplier;
import org.springframework.web.reactive.DispatcherHandler;
@@ -184,17 +182,13 @@ public class WebFluxEndpointManagementContextConfiguration {
private void process(Encoder<?> encoder) {
if (encoder instanceof JacksonJsonEncoder jacksonJsonEncoder) {
this.endpointJsonMapper.get()
.getSupportedTypes()
.forEach((type) -> jacksonJsonEncoder.registerMappersForType(type, this::registerForAllMimeTypes));
jacksonJsonEncoder.registerMappersForType(OperationResponseBody.class, (associations) -> {
JsonMapper jsonMapper = this.endpointJsonMapper.get().get();
MEDIA_TYPES.forEach((mimeType) -> associations.put(mimeType, jsonMapper));
});
}
}
private void registerForAllMimeTypes(Map<MimeType, JsonMapper> registrar) {
JsonMapper jsonMapper = this.endpointJsonMapper.get().get();
MEDIA_TYPES.forEach((mimeType) -> registrar.put(mimeType, jsonMapper));
}
}
}
@@ -21,7 +21,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import tools.jackson.databind.json.JsonMapper;
@@ -183,13 +182,10 @@ public class WebMvcEndpointManagementContextConfiguration {
}
private void configure(JacksonJsonHttpMessageConverter converter) {
this.endpointJsonMapper.getSupportedTypes()
.forEach((type) -> converter.registerMappersForType(type, this::registerForAllMimeTypes));
}
private void registerForAllMimeTypes(Map<MediaType, JsonMapper> registrar) {
JsonMapper jsonMapper = this.endpointJsonMapper.get();
MEDIA_TYPES.forEach((mimeType) -> registrar.put(mimeType, jsonMapper));
converter.registerMappersForType(OperationResponseBody.class, (associations) -> {
JsonMapper jsonMapper = this.endpointJsonMapper.get();
MEDIA_TYPES.forEach((mimeType) -> associations.put(mimeType, jsonMapper));
});
}
}