Upgrade to Jackson 2.7.2
Closes gh-5081
This commit is contained in:
@@ -310,7 +310,7 @@ public class ConfigurationPropertiesReportEndpoint
|
||||
|
||||
private boolean isReadable(BeanDescription beanDesc, BeanPropertyWriter writer) {
|
||||
String parentType = beanDesc.getType().getRawClass().getName();
|
||||
String type = writer.getPropertyType().getName();
|
||||
String type = writer.getType().getTypeName();
|
||||
AnnotatedMethod setter = findSetter(beanDesc, writer);
|
||||
// If there's a setter, we assume it's OK to report on the value,
|
||||
// similarly, if there's no setter but the package names match, we assume
|
||||
@@ -324,7 +324,7 @@ public class ConfigurationPropertiesReportEndpoint
|
||||
private AnnotatedMethod findSetter(BeanDescription beanDesc,
|
||||
BeanPropertyWriter writer) {
|
||||
String name = "set" + StringUtils.capitalize(writer.getName());
|
||||
Class<?> type = writer.getPropertyType();
|
||||
Class<?> type = writer.getType().getRawClass();
|
||||
AnnotatedMethod setter = beanDesc.findMethod(name, new Class<?>[] { type });
|
||||
// The enabled property of endpoints returns a boolean primitive but is set
|
||||
// using a Boolean class
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.boot.actuate.endpoint.jmx;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
@@ -40,6 +41,10 @@ public class EndpointMBean {
|
||||
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
private final JavaType listObject;
|
||||
|
||||
private final JavaType mapStringObject;
|
||||
|
||||
/**
|
||||
* Create a new {@link EndpointMBean} instance.
|
||||
* @param beanName the bean name
|
||||
@@ -53,6 +58,10 @@ public class EndpointMBean {
|
||||
Assert.notNull(objectMapper, "ObjectMapper must not be null");
|
||||
this.endpoint = endpoint;
|
||||
this.mapper = objectMapper;
|
||||
this.listObject = objectMapper.getTypeFactory()
|
||||
.constructParametricType(List.class, Object.class);
|
||||
this.mapStringObject = objectMapper.getTypeFactory()
|
||||
.constructParametricType(Map.class, String.class, Object.class);
|
||||
}
|
||||
|
||||
@ManagedAttribute(description = "Returns the class of the underlying endpoint")
|
||||
@@ -77,9 +86,9 @@ public class EndpointMBean {
|
||||
return result;
|
||||
}
|
||||
if (result.getClass().isArray() || result instanceof List) {
|
||||
return this.mapper.convertValue(result, List.class);
|
||||
return this.mapper.convertValue(result, this.listObject);
|
||||
}
|
||||
return this.mapper.convertValue(result, Map.class);
|
||||
return this.mapper.convertValue(result, this.mapStringObject);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,10 +17,12 @@
|
||||
package org.springframework.boot.actuate.endpoint.jmx;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -199,12 +201,12 @@ public class EndpointMBeanExporterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsonConversionWithDefaultObjectMapper() throws Exception {
|
||||
public void jsonMapConversionWithDefaultObjectMapper() throws Exception {
|
||||
this.context = new GenericApplicationContext();
|
||||
this.context.registerBeanDefinition("endpointMbeanExporter",
|
||||
new RootBeanDefinition(EndpointMBeanExporter.class));
|
||||
this.context.registerBeanDefinition("endpoint1",
|
||||
new RootBeanDefinition(JsonConversionEndpoint.class));
|
||||
new RootBeanDefinition(JsonMapConversionEndpoint.class));
|
||||
this.context.refresh();
|
||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||
Object response = mbeanExporter.getServer().invoke(
|
||||
@@ -215,7 +217,7 @@ public class EndpointMBeanExporterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsonConversionWithCustomObjectMapper() throws Exception {
|
||||
public void jsonMapConversionWithCustomObjectMapper() throws Exception {
|
||||
this.context = new GenericApplicationContext();
|
||||
ConstructorArgumentValues constructorArgs = new ConstructorArgumentValues();
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
@@ -225,7 +227,7 @@ public class EndpointMBeanExporterTests {
|
||||
new RootBeanDefinition(EndpointMBeanExporter.class, constructorArgs,
|
||||
null));
|
||||
this.context.registerBeanDefinition("endpoint1",
|
||||
new RootBeanDefinition(JsonConversionEndpoint.class));
|
||||
new RootBeanDefinition(JsonMapConversionEndpoint.class));
|
||||
this.context.refresh();
|
||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||
Object response = mbeanExporter.getServer().invoke(
|
||||
@@ -235,6 +237,22 @@ public class EndpointMBeanExporterTests {
|
||||
assertThat(((Map<?, ?>) response).get("date")).isInstanceOf(String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsonListConversion() throws Exception {
|
||||
this.context = new GenericApplicationContext();
|
||||
this.context.registerBeanDefinition("endpointMbeanExporter",
|
||||
new RootBeanDefinition(EndpointMBeanExporter.class));
|
||||
this.context.registerBeanDefinition("endpoint1",
|
||||
new RootBeanDefinition(JsonListConversionEndpoint.class));
|
||||
this.context.refresh();
|
||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||
Object response = mbeanExporter.getServer().invoke(
|
||||
getObjectName("endpoint1", this.context), "getData", new Object[0],
|
||||
new String[0]);
|
||||
assertThat(response).isInstanceOf(List.class);
|
||||
assertThat(((List<?>) response).get(0)).isInstanceOf(Long.class);
|
||||
}
|
||||
|
||||
private ObjectName getObjectName(String beanKey, GenericApplicationContext context)
|
||||
throws MalformedObjectNameException {
|
||||
return getObjectName("org.springframework.boot", beanKey, false, context);
|
||||
@@ -265,11 +283,11 @@ public class EndpointMBeanExporterTests {
|
||||
|
||||
}
|
||||
|
||||
public static class JsonConversionEndpoint
|
||||
public static class JsonMapConversionEndpoint
|
||||
extends AbstractEndpoint<Map<String, Object>> {
|
||||
|
||||
public JsonConversionEndpoint() {
|
||||
super("json-conversion");
|
||||
public JsonMapConversionEndpoint() {
|
||||
super("json-map-conversion");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -281,4 +299,18 @@ public class EndpointMBeanExporterTests {
|
||||
|
||||
}
|
||||
|
||||
public static class JsonListConversionEndpoint
|
||||
extends AbstractEndpoint<List<Object>> {
|
||||
|
||||
public JsonListConversionEndpoint() {
|
||||
super("json-list-conversion");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> invoke() {
|
||||
return Arrays.<Object>asList(new Date());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user