diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java index 4c1be68dad..d7f0a494f1 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java @@ -44,6 +44,7 @@ import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.core.env.StandardEnvironment; import org.springframework.lang.Nullable; +import org.springframework.util.ClassUtils; import org.springframework.util.PropertyPlaceholderHelper; import org.springframework.util.StringUtils; import org.springframework.util.SystemPropertyUtils; @@ -184,7 +185,8 @@ public class EnvironmentEndpoint { } protected Object stringifyIfNecessary(Object value) { - if (value == null || value.getClass().isPrimitive()) { + if (value == null || ClassUtils.isPrimitiveOrWrapper(value.getClass()) + || Number.class.isAssignableFrom(value.getClass())) { return value; } if (CharSequence.class.isAssignableFrom(value.getClass())) { diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/env/EnvironmentEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/env/EnvironmentEndpointTests.java index 313a67f312..acc99906bc 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/env/EnvironmentEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/env/EnvironmentEndpointTests.java @@ -19,6 +19,7 @@ package org.springframework.boot.actuate.env; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.math.BigInteger; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; @@ -199,7 +200,7 @@ class EnvironmentEndpointTests { } @Test - void propertyWithTypeOtherThanStringShouldNotFail() { + void propertyWithComplexTypeShouldNotFail() { ConfigurableEnvironment environment = emptyEnvironment(); environment.getPropertySources() .addFirst(singleKeyPropertySource("test", "foo", Collections.singletonMap("bar", "baz"))); @@ -208,6 +209,23 @@ class EnvironmentEndpointTests { assertThat(value).isEqualTo("Complex property type java.util.Collections$SingletonMap"); } + @Test + void propertyWithPrimitiveOrWrapperTypeIsHandledCorrectly() { + ConfigurableEnvironment environment = emptyEnvironment(); + Map map = new LinkedHashMap<>(); + map.put("char", 'a'); + map.put("integer", 100); + map.put("boolean", true); + map.put("biginteger", BigInteger.valueOf(200)); + environment.getPropertySources().addFirst(new MapPropertySource("test", map)); + EnvironmentDescriptor descriptor = new EnvironmentEndpoint(environment).environment(null); + Map properties = propertySources(descriptor).get("test").getProperties(); + assertThat(properties.get("char").getValue()).isEqualTo('a'); + assertThat(properties.get("integer").getValue()).isEqualTo(100); + assertThat(properties.get("boolean").getValue()).isEqualTo(true); + assertThat(properties.get("biginteger").getValue()).isEqualTo(BigInteger.valueOf(200)); + } + @Test void propertyWithCharSequenceTypeIsConvertedToString() throws Exception { ConfigurableEnvironment environment = emptyEnvironment();