Merge pull request #21704 from unix1982
* pr/21704: Polish 'Add origin support for empty YAML list and map' Add origin support for empty YAML list and map Closes gh-21704
This commit is contained in:
@@ -30,6 +30,7 @@ import org.yaml.snakeyaml.constructor.BaseConstructor;
|
|||||||
import org.yaml.snakeyaml.constructor.Constructor;
|
import org.yaml.snakeyaml.constructor.Constructor;
|
||||||
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||||
import org.yaml.snakeyaml.error.Mark;
|
import org.yaml.snakeyaml.error.Mark;
|
||||||
|
import org.yaml.snakeyaml.nodes.CollectionNode;
|
||||||
import org.yaml.snakeyaml.nodes.MappingNode;
|
import org.yaml.snakeyaml.nodes.MappingNode;
|
||||||
import org.yaml.snakeyaml.nodes.Node;
|
import org.yaml.snakeyaml.nodes.Node;
|
||||||
import org.yaml.snakeyaml.nodes.NodeTuple;
|
import org.yaml.snakeyaml.nodes.NodeTuple;
|
||||||
@@ -104,12 +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 MappingNode) {
|
if (node instanceof MappingNode) {
|
||||||
replaceMappingNodeKeys((MappingNode) node);
|
replaceMappingNodeKeys((MappingNode) node);
|
||||||
}
|
}
|
||||||
return super.constructObject(node);
|
return super.constructObject(node);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.springframework.boot.env;
|
package org.springframework.boot.env;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -120,6 +121,14 @@ class OriginTrackedYamlLoaderTests {
|
|||||||
assertThat(getLocation(nullValue)).isEqualTo("28:13");
|
assertThat(getLocation(nullValue)).isEqualTo("28:13");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void processEmptyListAndMap() {
|
||||||
|
OriginTrackedValue emptymap = getValue("emptymap");
|
||||||
|
OriginTrackedValue emptylist = getValue("emptylist");
|
||||||
|
assertThat(emptymap.getValue()).isEqualTo(Collections.emptyMap());
|
||||||
|
assertThat(emptylist.getValue()).isEqualTo(Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void unsupportedType() throws Exception {
|
void unsupportedType() throws Exception {
|
||||||
String yaml = "value: !!java.net.URL [!!java.lang.String [!!java.lang.StringBuilder [\"http://localhost:9000/\"]]]";
|
String yaml = "value: !!java.net.URL [!!java.lang.String [!!java.lang.StringBuilder [\"http://localhost:9000/\"]]]";
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ example:
|
|||||||
- bar2: bling
|
- bar2: bling
|
||||||
empty: ""
|
empty: ""
|
||||||
null-value: null
|
null-value: null
|
||||||
|
emptylist: []
|
||||||
|
emptymap: {}
|
||||||
---
|
---
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
|
|||||||
Reference in New Issue
Block a user