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
ff3af47e
Commit
ff3af47e
authored
Jan 10, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Watch out for non-Strings in YAML map keys
Fixes gh-205
parent
bd737053
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
1 deletion
+28
-1
YamlProcessor.java
...n/java/org/springframework/boot/config/YamlProcessor.java
+15
-1
YamlProcessorTests.java
...a/org/springframework/boot/config/YamlProcessorTests.java
+13
-0
No files found.
spring-boot/src/main/java/org/springframework/boot/config/YamlProcessor.java
View file @
ff3af47e
...
...
@@ -19,6 +19,7 @@ package org.springframework.boot.config;
import
java.io.IOException
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
...
...
@@ -164,7 +165,20 @@ public class YamlProcessor {
@SuppressWarnings
(
"unchecked"
)
private
Map
<
String
,
Object
>
asMap
(
Object
object
)
{
return
(
Map
<
String
,
Object
>)
object
;
// YAML can have numbers as keys
Map
<
String
,
Object
>
result
=
new
LinkedHashMap
<
String
,
Object
>();
Map
<
Object
,
Object
>
map
=
(
Map
<
Object
,
Object
>)
object
;
for
(
Entry
<
Object
,
Object
>
entry
:
map
.
entrySet
())
{
Object
key
=
entry
.
getKey
();
if
(
key
instanceof
CharSequence
)
{
result
.
put
(
key
.
toString
(),
entry
.
getValue
());
}
else
{
// It has to be a map key in this case
result
.
put
(
"["
+
key
.
toString
()
+
"]"
,
entry
.
getValue
());
}
}
return
result
;
}
private
boolean
process
(
Map
<
String
,
Object
>
map
,
MatchCallback
callback
)
{
...
...
spring-boot/src/test/java/org/springframework/boot/config/YamlProcessorTests.java
View file @
ff3af47e
...
...
@@ -63,4 +63,17 @@ public class YamlProcessorTests {
});
}
@Test
public
void
integerKeyBehaves
()
{
this
.
processor
.
setResources
(
new
Resource
[]
{
new
ByteArrayResource
(
"foo: bar\n1: bar"
.
getBytes
())
});
this
.
processor
.
process
(
new
MatchCallback
()
{
@Override
public
void
process
(
Properties
properties
,
Map
<
String
,
Object
>
map
)
{
assertEquals
(
"bar"
,
properties
.
get
(
"[1]"
));
assertEquals
(
2
,
properties
.
size
());
}
});
}
}
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