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
11f0f668
Commit
11f0f668
authored
Aug 30, 2018
by
artsiom
Committed by
Stephane Nicoll
Sep 03, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Throw an exception on invalid syntax in SPRING_APPLICATION_JSON
Closes gh-14251
parent
5a1aefc7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
11 deletions
+15
-11
SpringApplicationJsonEnvironmentPostProcessor.java
...ot/env/SpringApplicationJsonEnvironmentPostProcessor.java
+6
-11
SpringApplicationJsonEnvironmentPostProcessorTests.java
...v/SpringApplicationJsonEnvironmentPostProcessorTests.java
+9
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessor.java
View file @
11f0f668
...
@@ -50,6 +50,7 @@ import org.springframework.web.context.support.StandardServletEnvironment;
...
@@ -50,6 +50,7 @@ import org.springframework.web.context.support.StandardServletEnvironment;
* @author Dave Syer
* @author Dave Syer
* @author Phillip Webb
* @author Phillip Webb
* @author Madhura Bhave
* @author Madhura Bhave
* @author Artsiom Yudovin
* @since 1.3.0
* @since 1.3.0
*/
*/
public
class
SpringApplicationJsonEnvironmentPostProcessor
public
class
SpringApplicationJsonEnvironmentPostProcessor
...
@@ -97,17 +98,11 @@ public class SpringApplicationJsonEnvironmentPostProcessor
...
@@ -97,17 +98,11 @@ public class SpringApplicationJsonEnvironmentPostProcessor
private
void
processJson
(
ConfigurableEnvironment
environment
,
private
void
processJson
(
ConfigurableEnvironment
environment
,
JsonPropertyValue
propertyValue
)
{
JsonPropertyValue
propertyValue
)
{
try
{
JsonParser
parser
=
JsonParserFactory
.
getJsonParser
();
JsonParser
parser
=
JsonParserFactory
.
getJsonParser
();
Map
<
String
,
Object
>
map
=
parser
.
parseMap
(
propertyValue
.
getJson
());
Map
<
String
,
Object
>
map
=
parser
.
parseMap
(
propertyValue
.
getJson
());
if
(!
map
.
isEmpty
())
{
if
(!
map
.
isEmpty
())
{
addJsonPropertySource
(
environment
,
addJsonPropertySource
(
environment
,
new
JsonPropertySource
(
propertyValue
,
flatten
(
map
)));
new
JsonPropertySource
(
propertyValue
,
flatten
(
map
)));
}
}
catch
(
Exception
ex
)
{
logger
.
warn
(
"Cannot parse JSON for spring.application.json: "
+
propertyValue
.
getJson
(),
ex
);
}
}
}
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessorTests.java
View file @
11f0f668
...
@@ -16,8 +16,11 @@
...
@@ -16,8 +16,11 @@
package
org
.
springframework
.
boot
.
env
;
package
org
.
springframework
.
boot
.
env
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.springframework.boot.json.JsonParseException
;
import
org.springframework.boot.origin.PropertySourceOrigin
;
import
org.springframework.boot.origin.PropertySourceOrigin
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.PropertySource
;
import
org.springframework.core.env.PropertySource
;
...
@@ -32,15 +35,21 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -32,15 +35,21 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer
* @author Dave Syer
* @author Madhura Bhave
* @author Madhura Bhave
* @author Phillip Webb
* @author Phillip Webb
* @author Artsiom Yudovin
*/
*/
public
class
SpringApplicationJsonEnvironmentPostProcessorTests
{
public
class
SpringApplicationJsonEnvironmentPostProcessorTests
{
@Rule
public
ExpectedException
expected
=
ExpectedException
.
none
();
private
SpringApplicationJsonEnvironmentPostProcessor
processor
=
new
SpringApplicationJsonEnvironmentPostProcessor
();
private
SpringApplicationJsonEnvironmentPostProcessor
processor
=
new
SpringApplicationJsonEnvironmentPostProcessor
();
private
ConfigurableEnvironment
environment
=
new
StandardEnvironment
();
private
ConfigurableEnvironment
environment
=
new
StandardEnvironment
();
@Test
@Test
public
void
error
()
{
public
void
error
()
{
this
.
expected
.
expect
(
JsonParseException
.
class
);
this
.
expected
.
expectMessage
(
"Cannot parse JSON"
);
assertThat
(
this
.
environment
.
resolvePlaceholders
(
"${foo:}"
)).
isEmpty
();
assertThat
(
this
.
environment
.
resolvePlaceholders
(
"${foo:}"
)).
isEmpty
();
TestPropertySourceUtils
.
addInlinedPropertiesToEnvironment
(
this
.
environment
,
TestPropertySourceUtils
.
addInlinedPropertiesToEnvironment
(
this
.
environment
,
"spring.application.json=foo:bar"
);
"spring.application.json=foo:bar"
);
...
...
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