Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
429cd8d1
Commit
429cd8d1
authored
Aug 23, 2018
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize use of Jackson ObjectMapper instances
Closes gh-1789
parent
60eace17
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
4 deletions
+45
-4
ConfigurationPropertiesReportEndpoint.java
...ext/properties/ConfigurationPropertiesReportEndpoint.java
+11
-3
JacksonJsonParser.java
...java/org/springframework/boot/json/JacksonJsonParser.java
+14
-0
JacksonJsonParserTests.java
...org/springframework/boot/json/JacksonJsonParserTests.java
+20
-1
No files found.
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpoint.java
View file @
429cd8d1
...
@@ -79,6 +79,8 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
...
@@ -79,6 +79,8 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
private
ApplicationContext
context
;
private
ApplicationContext
context
;
private
ObjectMapper
objectMapper
;
@Override
@Override
public
void
setApplicationContext
(
ApplicationContext
context
)
throws
BeansException
{
public
void
setApplicationContext
(
ApplicationContext
context
)
throws
BeansException
{
this
.
context
=
context
;
this
.
context
=
context
;
...
@@ -94,13 +96,11 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
...
@@ -94,13 +96,11 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
}
}
private
ApplicationConfigurationProperties
extract
(
ApplicationContext
context
)
{
private
ApplicationConfigurationProperties
extract
(
ApplicationContext
context
)
{
ObjectMapper
mapper
=
new
ObjectMapper
();
configureObjectMapper
(
mapper
);
Map
<
String
,
ContextConfigurationProperties
>
contextProperties
=
new
HashMap
<>();
Map
<
String
,
ContextConfigurationProperties
>
contextProperties
=
new
HashMap
<>();
ApplicationContext
target
=
context
;
ApplicationContext
target
=
context
;
while
(
target
!=
null
)
{
while
(
target
!=
null
)
{
contextProperties
.
put
(
target
.
getId
(),
contextProperties
.
put
(
target
.
getId
(),
describeConfigurationProperties
(
target
,
mapper
));
describeConfigurationProperties
(
target
,
getObjectMapper
()
));
target
=
target
.
getParent
();
target
=
target
.
getParent
();
}
}
return
new
ApplicationConfigurationProperties
(
contextProperties
);
return
new
ApplicationConfigurationProperties
(
contextProperties
);
...
@@ -179,6 +179,14 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
...
@@ -179,6 +179,14 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
applySerializationModifier
(
mapper
);
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.
* Ensure only bindable and non-cyclic bean properties are reported.
* @param mapper the object mapper
* @param mapper the object mapper
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JacksonJsonParser.java
View file @
429cd8d1
...
@@ -36,6 +36,20 @@ public class JacksonJsonParser extends AbstractJsonParser {
...
@@ -36,6 +36,20 @@ public class JacksonJsonParser extends AbstractJsonParser {
private
ObjectMapper
objectMapper
;
// Late binding
private
ObjectMapper
objectMapper
;
// Late binding
/**
* Creates a instance with the specified {@link ObjectMapper}.
* @param objectMapper the object mapper to use
*/
public
JacksonJsonParser
(
ObjectMapper
objectMapper
)
{
this
.
objectMapper
=
objectMapper
;
}
/**
* Creates an instance with a default {@link ObjectMapper} that is created lazily.
*/
public
JacksonJsonParser
()
{
}
@Override
@Override
public
Map
<
String
,
Object
>
parseMap
(
String
json
)
{
public
Map
<
String
,
Object
>
parseMap
(
String
json
)
{
return
tryParse
(()
->
getObjectMapper
().
readValue
(
json
,
MAP_TYPE
),
return
tryParse
(()
->
getObjectMapper
().
readValue
(
json
,
MAP_TYPE
),
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/json/JacksonJsonParserTests.java
View file @
429cd8d1
/*
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -16,10 +16,22 @@
...
@@ -16,10 +16,22 @@
package
org
.
springframework
.
boot
.
json
;
package
org
.
springframework
.
boot
.
json
;
import
java.io.IOException
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.junit.Test
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
spy
;
import
static
org
.
mockito
.
Mockito
.
verify
;
/**
/**
* Tests for {@link JacksonJsonParser}.
* Tests for {@link JacksonJsonParser}.
*
*
* @author Dave Syer
* @author Dave Syer
* @author Stephane Nicoll
*/
*/
public
class
JacksonJsonParserTests
extends
AbstractJsonParserTests
{
public
class
JacksonJsonParserTests
extends
AbstractJsonParserTests
{
...
@@ -28,4 +40,11 @@ public class JacksonJsonParserTests extends AbstractJsonParserTests {
...
@@ -28,4 +40,11 @@ public class JacksonJsonParserTests extends AbstractJsonParserTests {
return
new
JacksonJsonParser
();
return
new
JacksonJsonParser
();
}
}
@Test
public
void
instanceWithSpecificObjectMapper
()
throws
IOException
{
ObjectMapper
objectMapper
=
spy
(
new
ObjectMapper
());
new
JacksonJsonParser
(
objectMapper
).
parseMap
(
"{}"
);
verify
(
objectMapper
).
readValue
(
eq
(
"{}"
),
any
(
TypeReference
.
class
));
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment