Optimize use of Jackson ObjectMapper instances
Closes gh-1789
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user