Skip to content

Commit e01b362

Browse files
committed
Revert Support pluggable types for EndpointJsonMapper
Closes gh-46534
1 parent 02b2d03 commit e01b362

File tree

4 files changed

+10
-57
lines changed

4 files changed

+10
-57
lines changed

module/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jackson/JacksonEndpointAutoConfiguration.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.endpoint.jackson;
1818

19-
import java.util.HashSet;
20-
import java.util.Set;
21-
2219
import com.fasterxml.jackson.annotation.JsonInclude.Include;
2320
import tools.jackson.databind.ObjectMapper;
2421
import tools.jackson.databind.json.JsonMapper;
@@ -29,7 +26,6 @@
2926
import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty;
3027
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
3128
import org.springframework.context.annotation.Bean;
32-
import org.springframework.util.ClassUtils;
3329

3430
/**
3531
* {@link EnableAutoConfiguration Auto-configuration} for Endpoint Jackson support.
@@ -40,8 +36,6 @@
4036
@AutoConfiguration
4137
public final class JacksonEndpointAutoConfiguration {
4238

43-
private static final String CONTRIBUTED_HEALTH = "org.springframework.boot.health.contributor.ContributedHealth";
44-
4539
@Bean
4640
@ConditionalOnBooleanProperty(name = "management.endpoints.jackson.isolated-object-mapper", matchIfMissing = true)
4741
@ConditionalOnClass(ObjectMapper.class)
@@ -50,24 +44,7 @@ EndpointJsonMapper endpointJsonMapper() {
5044
.changeDefaultPropertyInclusion(
5145
(value) -> value.withValueInclusion(Include.NON_NULL).withContentInclusion(Include.NON_NULL))
5246
.build();
53-
Set<Class<?>> supportedTypes = new HashSet<>(EndpointJsonMapper.DEFAULT_SUPPORTED_TYPES);
54-
if (ClassUtils.isPresent(CONTRIBUTED_HEALTH, null)) {
55-
supportedTypes.add(ClassUtils.resolveClassName(CONTRIBUTED_HEALTH, null));
56-
}
57-
return new EndpointJsonMapper() {
58-
59-
@Override
60-
public JsonMapper get() {
61-
return jsonMapper;
62-
}
63-
64-
@Override
65-
public Set<Class<?>> getSupportedTypes() {
66-
return supportedTypes;
67-
}
68-
69-
};
70-
47+
return () -> jsonMapper;
7148
}
7249

7350
}

module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jackson/EndpointJsonMapper.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.boot.actuate.endpoint.jackson;
1818

19-
import java.util.Set;
20-
2119
import tools.jackson.databind.json.JsonMapper;
2220

2321
import org.springframework.boot.actuate.endpoint.OperationResponseBody;
@@ -30,26 +28,14 @@
3028
* @since 4.0.0
3129
* @see OperationResponseBody
3230
*/
31+
@FunctionalInterface
3332
public interface EndpointJsonMapper {
3433

35-
/**
36-
* The default supported types.
37-
*/
38-
Set<Class<?>> DEFAULT_SUPPORTED_TYPES = Set.of(OperationResponseBody.class);
39-
4034
/**
4135
* Return the {@link JsonMapper} that should be used to serialize
4236
* {@link OperationResponseBody} endpoint results.
4337
* @return the object mapper
4438
*/
4539
JsonMapper get();
4640

47-
/**
48-
* Return the types that this endpoint mapper supports.
49-
* @return the supported types
50-
*/
51-
default Set<Class<?>> getSupportedTypes() {
52-
return DEFAULT_SUPPORTED_TYPES;
53-
}
54-
5541
}

module/spring-boot-webflux/src/main/java/org/springframework/boot/webflux/autoconfigure/actuate/web/WebFluxEndpointManagementContextConfiguration.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Collection;
2222
import java.util.Collections;
2323
import java.util.List;
24-
import java.util.Map;
2524
import java.util.function.Supplier;
2625

2726
import tools.jackson.databind.json.JsonMapper;
@@ -68,7 +67,6 @@
6867
import org.springframework.http.codec.ServerCodecConfigurer;
6968
import org.springframework.http.codec.json.JacksonJsonEncoder;
7069
import org.springframework.http.server.reactive.HttpHandler;
71-
import org.springframework.util.MimeType;
7270
import org.springframework.util.StringUtils;
7371
import org.springframework.util.function.SingletonSupplier;
7472
import org.springframework.web.reactive.DispatcherHandler;
@@ -184,17 +182,13 @@ private void process(ServerCodecConfigurer configurer) {
184182

185183
private void process(Encoder<?> encoder) {
186184
if (encoder instanceof JacksonJsonEncoder jacksonJsonEncoder) {
187-
this.endpointJsonMapper.get()
188-
.getSupportedTypes()
189-
.forEach((type) -> jacksonJsonEncoder.registerMappersForType(type, this::registerForAllMimeTypes));
185+
jacksonJsonEncoder.registerMappersForType(OperationResponseBody.class, (associations) -> {
186+
JsonMapper jsonMapper = this.endpointJsonMapper.get().get();
187+
MEDIA_TYPES.forEach((mimeType) -> associations.put(mimeType, jsonMapper));
188+
});
190189
}
191190
}
192191

193-
private void registerForAllMimeTypes(Map<MimeType, JsonMapper> registrar) {
194-
JsonMapper jsonMapper = this.endpointJsonMapper.get().get();
195-
MEDIA_TYPES.forEach((mimeType) -> registrar.put(mimeType, jsonMapper));
196-
}
197-
198192
}
199193

200194
}

module/spring-boot-webmvc/src/main/java/org/springframework/boot/webmvc/autoconfigure/actuate/web/WebMvcEndpointManagementContextConfiguration.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Collection;
2222
import java.util.Collections;
2323
import java.util.List;
24-
import java.util.Map;
2524

2625
import tools.jackson.databind.json.JsonMapper;
2726

@@ -183,13 +182,10 @@ public void configureMessageConverters(ServerBuilder builder) {
183182
}
184183

185184
private void configure(JacksonJsonHttpMessageConverter converter) {
186-
this.endpointJsonMapper.getSupportedTypes()
187-
.forEach((type) -> converter.registerMappersForType(type, this::registerForAllMimeTypes));
188-
}
189-
190-
private void registerForAllMimeTypes(Map<MediaType, JsonMapper> registrar) {
191-
JsonMapper jsonMapper = this.endpointJsonMapper.get();
192-
MEDIA_TYPES.forEach((mimeType) -> registrar.put(mimeType, jsonMapper));
185+
converter.registerMappersForType(OperationResponseBody.class, (associations) -> {
186+
JsonMapper jsonMapper = this.endpointJsonMapper.get();
187+
MEDIA_TYPES.forEach((mimeType) -> associations.put(mimeType, jsonMapper));
188+
});
193189
}
194190

195191
}

0 commit comments

Comments
 (0)