Skip to content

Commit

Permalink
Fix null array values in HOCON/JSON config parser. (#2731)
Browse files Browse the repository at this point in the history
Resolves #2720 (follow-up)
  • Loading branch information
romain-grecourt authored Feb 4, 2021
1 parent d894ea8 commit ac1b609
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ private static ListNode fromList(ConfigList list) {
} else if (value instanceof ConfigObject) {
builder.addObject(fromConfig((ConfigObject) value));
} else {
builder.addValue(value.unwrapped().toString());
Object unwrapped = value.unwrapped();
if (unwrapped == null) {
builder.addValue("");
} else {
builder.addValue(String.valueOf(unwrapped));
}
}
});
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -292,6 +293,9 @@ void testParserFromJson() {

property = config.get("nulls.null").asString().asOptional();
assertThat(property, is(Optional.of("")));

List<String> properties = config.get("nulls-array").asList(String.class).get();
assertThat(properties, hasItems("test", ""));
}

//
Expand Down
3 changes: 2 additions & 1 deletion config/hocon/src/test/resources/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
},
"nulls": {
"null": null
}
},
"nulls-array": ["test", null]
}

0 comments on commit ac1b609

Please sign in to comment.