Commit 47d85bb4 authored by dreis2211's avatar dreis2211 Committed by Stephane Nicoll

Add Duration support in /configprops endpoint

See gh-16539
parent bc90d48f
...@@ -41,6 +41,7 @@ import com.fasterxml.jackson.databind.ser.PropertyWriter; ...@@ -41,6 +41,7 @@ import com.fasterxml.jackson.databind.ser.PropertyWriter;
import com.fasterxml.jackson.databind.ser.SerializerFactory; import com.fasterxml.jackson.databind.ser.SerializerFactory;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
...@@ -172,10 +173,12 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext ...@@ -172,10 +173,12 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
*/ */
protected void configureObjectMapper(ObjectMapper mapper) { protected void configureObjectMapper(ObjectMapper mapper) {
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.configure(MapperFeature.USE_STD_BEAN_NAMING, true); mapper.configure(MapperFeature.USE_STD_BEAN_NAMING, true);
mapper.setSerializationInclusion(Include.NON_NULL); mapper.setSerializationInclusion(Include.NON_NULL);
applyConfigurationPropertiesFilter(mapper); applyConfigurationPropertiesFilter(mapper);
applySerializationModifier(mapper); applySerializationModifier(mapper);
mapper.registerModule(new JavaTimeModule());
} }
private ObjectMapper getObjectMapper() { private ObjectMapper getObjectMapper() {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package org.springframework.boot.actuate.context.properties; package org.springframework.boot.actuate.context.properties;
import java.time.Duration;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
...@@ -157,6 +158,16 @@ public class ConfigurationPropertiesReportEndpointTests { ...@@ -157,6 +158,16 @@ public class ConfigurationPropertiesReportEndpointTests {
}); });
} }
@Test
public void duration() {
load((context, properties) -> {
Map<String, Object> nestedProperties = properties.getBeans()
.get("testProperties").getProperties();
assertThat(nestedProperties.get("duration"))
.isEqualTo(Duration.ofSeconds(10).toString());
});
}
@Test @Test
public void singleLetterProperty() { public void singleLetterProperty() {
load((context, properties) -> { load((context, properties) -> {
...@@ -276,6 +287,8 @@ public class ConfigurationPropertiesReportEndpointTests { ...@@ -276,6 +287,8 @@ public class ConfigurationPropertiesReportEndpointTests {
private String nullValue = null; private String nullValue = null;
private Duration duration = Duration.ofSeconds(10);
public TestProperties() { public TestProperties() {
this.secrets.put("mine", "myPrivateThing"); this.secrets.put("mine", "myPrivateThing");
this.secrets.put("yours", "yourPrivateThing"); this.secrets.put("yours", "yourPrivateThing");
...@@ -379,6 +392,14 @@ public class ConfigurationPropertiesReportEndpointTests { ...@@ -379,6 +392,14 @@ public class ConfigurationPropertiesReportEndpointTests {
this.nullValue = nullValue; this.nullValue = nullValue;
} }
public Duration getDuration() {
return this.duration;
}
public void setDuration(Duration duration) {
this.duration = duration;
}
public static class Hidden { public static class Hidden {
private String mine = "mySecret"; private String mine = "mySecret";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment