Skip to content

Commit 51ee702

Browse files
committed
Allow configprops endpoint stringify primitive wrappers
Update `ConfigurationPropertiesReportEndpoint` so that primitive wrapper input values in the Environment are stringified for display. Fixes gh-36076
1 parent 4d1defd commit 51ee702

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ private Map<String, Object> getInput(ConfigurationProperty candidate, Object san
394394
}
395395

396396
private Object stringifyIfNecessary(Object value) {
397-
if (value == null || value.getClass().isPrimitive()) {
397+
if (value == null || ClassUtils.isPrimitiveOrWrapper(value.getClass()) || value instanceof String) {
398398
return value;
399399
}
400400
if (CharSequence.class.isAssignableFrom(value.getClass())) {

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointTests.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444
import org.springframework.context.ConfigurableApplicationContext;
4545
import org.springframework.context.annotation.Bean;
4646
import org.springframework.context.annotation.Configuration;
47+
import org.springframework.core.env.ConfigurableEnvironment;
4748
import org.springframework.core.env.Environment;
49+
import org.springframework.core.env.MapPropertySource;
50+
import org.springframework.core.env.PropertySource;
4851
import org.springframework.mock.env.MockPropertySource;
4952
import org.springframework.util.unit.DataSize;
5053

@@ -143,6 +146,21 @@ void descriptorWithDurationProperty() {
143146
.isEqualTo(Duration.ofSeconds(10).toString())));
144147
}
145148

149+
@Test // gh-36076
150+
void descriptorWithWrapperProperty() {
151+
this.contextRunner.withUserConfiguration(TestPropertiesConfiguration.class).withInitializer((context) -> {
152+
ConfigurableEnvironment environment = context.getEnvironment();
153+
Map<String, Object> map = Collections.singletonMap("test.wrapper", 10);
154+
PropertySource<?> propertySource = new MapPropertySource("test", map);
155+
environment.getPropertySources().addLast(propertySource);
156+
})
157+
.run(assertProperties("test", (properties) -> assertThat(properties.get("wrapper")).isEqualTo(10),
158+
(inputs) -> {
159+
Map<String, Object> wrapper = (Map<String, Object>) inputs.get("wrapper");
160+
assertThat(wrapper.get("value")).isEqualTo(10);
161+
}));
162+
}
163+
146164
@Test
147165
void descriptorWithNonCamelCaseProperty() {
148166
this.contextRunner.withUserConfiguration(MixedCasePropertiesConfiguration.class)
@@ -476,6 +494,8 @@ public static class TestProperties {
476494

477495
private String ignored = "dummy";
478496

497+
private Integer wrapper;
498+
479499
public String getDbPassword() {
480500
return this.dbPassword;
481501
}
@@ -512,6 +532,14 @@ public String getIgnored() {
512532
return this.ignored;
513533
}
514534

535+
public Integer getWrapper() {
536+
return this.wrapper;
537+
}
538+
539+
public void setWrapper(Integer wrapper) {
540+
this.wrapper = wrapper;
541+
}
542+
515543
}
516544

517545
@Configuration(proxyBeanMethods = false)

0 commit comments

Comments
 (0)