Add Duration support in /configprops endpoint

See gh-16539
pull/16930/head
dreis2211 6 years ago committed by Stephane Nicoll
parent bc90d48f72
commit 47d85bb4fe

@ -41,6 +41,7 @@ import com.fasterxml.jackson.databind.ser.PropertyWriter;
import com.fasterxml.jackson.databind.ser.SerializerFactory;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
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.LogFactory;
@ -172,10 +173,12 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
*/
protected void configureObjectMapper(ObjectMapper mapper) {
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.setSerializationInclusion(Include.NON_NULL);
applyConfigurationPropertiesFilter(mapper);
applySerializationModifier(mapper);
mapper.registerModule(new JavaTimeModule());
}
private ObjectMapper getObjectMapper() {

@ -16,6 +16,7 @@
package org.springframework.boot.actuate.context.properties;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -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
public void singleLetterProperty() {
load((context, properties) -> {
@ -276,6 +287,8 @@ public class ConfigurationPropertiesReportEndpointTests {
private String nullValue = null;
private Duration duration = Duration.ofSeconds(10);
public TestProperties() {
this.secrets.put("mine", "myPrivateThing");
this.secrets.put("yours", "yourPrivateThing");
@ -379,6 +392,14 @@ public class ConfigurationPropertiesReportEndpointTests {
this.nullValue = nullValue;
}
public Duration getDuration() {
return this.duration;
}
public void setDuration(Duration duration) {
this.duration = duration;
}
public static class Hidden {
private String mine = "mySecret";

Loading…
Cancel
Save