Skip to content

Commit 2f6d05d

Browse files
committed
Fix parsing of String value in json
Closes gh-11992
1 parent da01744 commit 2f6d05d

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

spring-boot/src/main/java/org/springframework/boot/json/BasicJsonParser.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@
3131
*
3232
* @author Dave Syer
3333
* @author Jean de Klerk
34+
* @author Stephane Nicoll
3435
* @since 1.2.0
3536
* @see JsonParserFactory
3637
*/
@@ -112,12 +113,7 @@ private Map<String, Object> parseMapInternal(String json) {
112113
for (String pair : tokenize(json)) {
113114
String[] values = StringUtils.trimArrayElements(StringUtils.split(pair, ":"));
114115
String key = trimLeadingCharacter(trimTrailingCharacter(values[0], '"'), '"');
115-
Object value = null;
116-
if (values.length > 0) {
117-
String string = trimLeadingCharacter(
118-
trimTrailingCharacter(values[1], '"'), '"');
119-
value = parseInternal(string);
120-
}
116+
Object value = parseInternal(values[1]);
121117
map.put(key, value);
122118
}
123119
return map;

spring-boot/src/test/java/org/springframework/boot/json/AbstractJsonParserTests.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -56,6 +56,13 @@ public void doubleValue() {
5656
assertThat(map.get("spam")).isEqualTo(1.23d);
5757
}
5858

59+
@Test
60+
public void stringContainingNumber() {
61+
Map<String, Object> map = this.parser.parseMap("{\"foo\":\"123\"}");
62+
assertThat(map).hasSize(1);
63+
assertThat(map.get("foo")).isEqualTo("123");
64+
}
65+
5966
@Test
6067
public void emptyMap() {
6168
Map<String, Object> map = this.parser.parseMap("{}");

0 commit comments

Comments
 (0)