Commit bd2a2521 authored by Phillip Webb's avatar Phillip Webb

Polish 'Add origin support for empty YAML list and map'

See gh-21704
parent f18d564a
...@@ -105,15 +105,15 @@ class OriginTrackedYamlLoader extends YamlProcessor { ...@@ -105,15 +105,15 @@ class OriginTrackedYamlLoader extends YamlProcessor {
@Override @Override
protected Object constructObject(Node node) { protected Object constructObject(Node node) {
if (node instanceof CollectionNode && ((CollectionNode<?>) node).getValue().isEmpty()) {
return constructTrackedObject(node, super.constructObject(node));
}
if (node instanceof ScalarNode) { if (node instanceof ScalarNode) {
if (!(node instanceof KeyScalarNode)) { if (!(node instanceof KeyScalarNode)) {
return constructTrackedObject(node, super.constructObject(node)); return constructTrackedObject(node, super.constructObject(node));
} }
} }
else if (node instanceof CollectionNode && ((CollectionNode<?>) node).getValue().isEmpty()) { if (node instanceof MappingNode) {
return constructTrackedObject(node, super.constructObject(node));
}
else if (node instanceof MappingNode) {
replaceMappingNodeKeys((MappingNode) node); replaceMappingNodeKeys((MappingNode) node);
} }
return super.constructObject(node); return super.constructObject(node);
......
...@@ -125,8 +125,8 @@ class OriginTrackedYamlLoaderTests { ...@@ -125,8 +125,8 @@ class OriginTrackedYamlLoaderTests {
void processEmptyListAndMap() { void processEmptyListAndMap() {
OriginTrackedValue emptymap = getValue("emptymap"); OriginTrackedValue emptymap = getValue("emptymap");
OriginTrackedValue emptylist = getValue("emptylist"); OriginTrackedValue emptylist = getValue("emptylist");
assertThat(emptymap.getValue()).isEqualTo(Collections.EMPTY_MAP); assertThat(emptymap.getValue()).isEqualTo(Collections.emptyMap());
assertThat(emptylist.getValue()).isEqualTo(Collections.EMPTY_LIST); assertThat(emptylist.getValue()).isEqualTo(Collections.emptyList());
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment