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
5ed71560
Commit
5ed71560
authored
Oct 31, 2015
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for lists in SPRING_APPLICATION_JSON
parent
986275c7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
7 deletions
+39
-7
SpringApplicationJsonEnvironmentPostProcessor.java
...ot/env/SpringApplicationJsonEnvironmentPostProcessor.java
+21
-7
SpringApplicationJsonEnvironmentPostProcessorTests.java
...v/SpringApplicationJsonEnvironmentPostProcessorTests.java
+18
-0
No files found.
spring-boot/src/main/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessor.java
View file @
5ed71560
...
...
@@ -16,6 +16,7 @@
package
org
.
springframework
.
boot
.
env
;
import
java.util.Collection
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
...
...
@@ -116,15 +117,28 @@ public class SpringApplicationJsonEnvironmentPostProcessor
for
(
String
key
:
map
.
keySet
())
{
String
name
=
prefix
+
key
;
Object
value
=
map
.
get
(
key
);
if
(
value
instanceof
Map
)
{
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
nested
=
(
Map
<
String
,
Object
>)
value
;
flatten
(
name
,
result
,
nested
);
}
else
{
result
.
put
(
name
,
value
);
extract
(
name
,
result
,
value
);
}
}
private
void
extract
(
String
name
,
Map
<
String
,
Object
>
result
,
Object
value
)
{
if
(
value
instanceof
Map
)
{
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
nested
=
(
Map
<
String
,
Object
>)
value
;
flatten
(
name
,
result
,
nested
);
}
if
(
value
instanceof
Collection
)
{
@SuppressWarnings
(
"unchecked"
)
Collection
<
Object
>
nested
=
(
Collection
<
Object
>)
value
;
int
index
=
0
;
for
(
Object
object
:
nested
)
{
extract
(
name
+
"["
+
index
+
"]"
,
result
,
object
);
index
++;
}
}
else
{
result
.
put
(
name
,
value
);
}
}
private
String
findPropertySource
(
MutablePropertySources
sources
)
{
...
...
spring-boot/src/test/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessorTests.java
View file @
5ed71560
...
...
@@ -95,4 +95,22 @@ public class SpringApplicationJsonEnvironmentPostProcessorTests {
assertEquals
(
"spam"
,
this
.
environment
.
resolvePlaceholders
(
"${foo.bar:}"
));
}
@Test
public
void
list
()
{
assertEquals
(
""
,
this
.
environment
.
resolvePlaceholders
(
"${foo[1]:}"
));
EnvironmentTestUtils
.
addEnvironment
(
this
.
environment
,
"SPRING_APPLICATION_JSON={\"foo\":[\"bar\",\"spam\"]}"
);
this
.
processor
.
postProcessEnvironment
(
this
.
environment
,
null
);
assertEquals
(
"spam"
,
this
.
environment
.
resolvePlaceholders
(
"${foo[1]:}"
));
}
@Test
public
void
listOfObject
()
{
assertEquals
(
""
,
this
.
environment
.
resolvePlaceholders
(
"${foo[0].bar:}"
));
EnvironmentTestUtils
.
addEnvironment
(
this
.
environment
,
"SPRING_APPLICATION_JSON={\"foo\":[{\"bar\":\"spam\"}]}"
);
this
.
processor
.
postProcessEnvironment
(
this
.
environment
,
null
);
assertEquals
(
"spam"
,
this
.
environment
.
resolvePlaceholders
(
"${foo[0].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