Optimize use of Jackson ObjectMapper instances

Closes gh-1789
This commit is contained in:
Stephane Nicoll
2018-08-23 14:09:48 +02:00
parent 60eace17d4
commit 429cd8d114
3 changed files with 45 additions and 4 deletions

View File

@@ -79,6 +79,8 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
private ApplicationContext context;
private ObjectMapper objectMapper;
@Override
public void setApplicationContext(ApplicationContext context) throws BeansException {
this.context = context;
@@ -94,13 +96,11 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
}
private ApplicationConfigurationProperties extract(ApplicationContext context) {
ObjectMapper mapper = new ObjectMapper();
configureObjectMapper(mapper);
Map<String, ContextConfigurationProperties> contextProperties = new HashMap<>();
ApplicationContext target = context;
while (target != null) {
contextProperties.put(target.getId(),
describeConfigurationProperties(target, mapper));
describeConfigurationProperties(target, getObjectMapper()));
target = target.getParent();
}
return new ApplicationConfigurationProperties(contextProperties);
@@ -179,6 +179,14 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
applySerializationModifier(mapper);
}
private ObjectMapper getObjectMapper() {
if (this.objectMapper == null) {
this.objectMapper = new ObjectMapper();
configureObjectMapper(this.objectMapper);
}
return this.objectMapper;
}
/**
* Ensure only bindable and non-cyclic bean properties are reported.
* @param mapper the object mapper