commit
0a8a0daff8
|
@ -49,7 +49,7 @@ public class BasicJsonParser extends AbstractJsonParser {
|
||||||
|
|
||||||
private List<Object> parseListInternal(String json) {
|
private List<Object> parseListInternal(String json) {
|
||||||
List<Object> list = new ArrayList<>();
|
List<Object> list = new ArrayList<>();
|
||||||
json = trimLeadingCharacter(trimTrailingCharacter(json, ']'), '[');
|
json = trimLeadingCharacter(trimTrailingCharacter(json, ']'), '[').trim();
|
||||||
for (String value : tokenize(json)) {
|
for (String value : tokenize(json)) {
|
||||||
list.add(parseInternal(value));
|
list.add(parseInternal(value));
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ public class BasicJsonParser extends AbstractJsonParser {
|
||||||
|
|
||||||
private Map<String, Object> parseMapInternal(String json) {
|
private Map<String, Object> parseMapInternal(String json) {
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
json = trimLeadingCharacter(trimTrailingCharacter(json, '}'), '{');
|
json = trimLeadingCharacter(trimTrailingCharacter(json, '}'), '{').trim();
|
||||||
for (String pair : tokenize(json)) {
|
for (String pair : tokenize(json)) {
|
||||||
String[] values = StringUtils.trimArrayElements(StringUtils.split(pair, ":"));
|
String[] values = StringUtils.trimArrayElements(StringUtils.split(pair, ":"));
|
||||||
String key = trimLeadingCharacter(trimTrailingCharacter(values[0], '"'), '"');
|
String key = trimLeadingCharacter(trimTrailingCharacter(values[0], '"'), '"');
|
||||||
|
@ -151,7 +151,7 @@ public class BasicJsonParser extends AbstractJsonParser {
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
if (build.length() > 0) {
|
if (build.length() > 0) {
|
||||||
list.add(build.toString());
|
list.add(build.toString().trim());
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,17 @@ abstract class AbstractJsonParserTests {
|
||||||
.parseMap("{\"foo\":[{\"foo\":\"bar\",\"spam\":1},{\"foo\":\"baz\",\"spam\":2}]}");
|
.parseMap("{\"foo\":[{\"foo\":\"bar\",\"spam\":1},{\"foo\":\"baz\",\"spam\":2}]}");
|
||||||
assertThat(map).hasSize(1);
|
assertThat(map).hasSize(1);
|
||||||
assertThat(((List<Object>) map.get("foo"))).hasSize(2);
|
assertThat(((List<Object>) map.get("foo"))).hasSize(2);
|
||||||
|
assertThat(map.get("foo")).asList().allMatch(Map.class::isInstance);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
void nestedLeadingAndTrailingWhitespace() {
|
||||||
|
Map<String, Object> map = this.parser.parseMap(
|
||||||
|
" {\"foo\": [ { \"foo\" : \"bar\" , \"spam\" : 1 } , { \"foo\" : \"baz\" , \"spam\" : 2 } ] } ");
|
||||||
|
assertThat(map).hasSize(1);
|
||||||
|
assertThat(((List<Object>) map.get("foo"))).hasSize(2);
|
||||||
|
assertThat(map.get("foo")).asList().allMatch(Map.class::isInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue