Skip to content

Commit

Permalink
Merge branch '2.1.x'
Browse files Browse the repository at this point in the history
Closes gh-18913
  • Loading branch information
wilkinsona committed Nov 7, 2019
2 parents dd4377e + a11661d commit 0a8a0da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Expand Up @@ -49,7 +49,7 @@ public List<Object> parseList(String json) {

private List<Object> parseListInternal(String json) {
List<Object> list = new ArrayList<>();
json = trimLeadingCharacter(trimTrailingCharacter(json, ']'), '[');
json = trimLeadingCharacter(trimTrailingCharacter(json, ']'), '[').trim();
for (String value : tokenize(json)) {
list.add(parseInternal(value));
}
Expand Down Expand Up @@ -97,7 +97,7 @@ private static String trimLeadingCharacter(String string, char c) {

private Map<String, Object> parseMapInternal(String json) {
Map<String, Object> map = new LinkedHashMap<>();
json = trimLeadingCharacter(trimTrailingCharacter(json, '}'), '{');
json = trimLeadingCharacter(trimTrailingCharacter(json, '}'), '{').trim();
for (String pair : tokenize(json)) {
String[] values = StringUtils.trimArrayElements(StringUtils.split(pair, ":"));
String key = trimLeadingCharacter(trimTrailingCharacter(values[0], '"'), '"');
Expand Down Expand Up @@ -151,7 +151,7 @@ else if (current == '\\') {
index++;
}
if (build.length() > 0) {
list.add(build.toString());
list.add(build.toString().trim());
}
return list;
}
Expand Down
Expand Up @@ -101,6 +101,17 @@ void mapOfLists() {
.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);
}

@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
Expand Down

0 comments on commit 0a8a0da

Please sign in to comment.