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:
commit
3bcbb0e594
|
@ -30,6 +30,7 @@ import org.yaml.snakeyaml.constructor.BaseConstructor;
|
|||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||
import org.yaml.snakeyaml.error.Mark;
|
||||
import org.yaml.snakeyaml.nodes.CollectionNode;
|
||||
import org.yaml.snakeyaml.nodes.MappingNode;
|
||||
import org.yaml.snakeyaml.nodes.Node;
|
||||
import org.yaml.snakeyaml.nodes.NodeTuple;
|
||||
|
@ -104,12 +105,15 @@ class OriginTrackedYamlLoader extends YamlProcessor {
|
|||
|
||||
@Override
|
||||
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 KeyScalarNode)) {
|
||||
return constructTrackedObject(node, super.constructObject(node));
|
||||
}
|
||||
}
|
||||
else if (node instanceof MappingNode) {
|
||||
if (node instanceof MappingNode) {
|
||||
replaceMappingNodeKeys((MappingNode) node);
|
||||
}
|
||||
return super.constructObject(node);
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.boot.env;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -120,6 +121,14 @@ class OriginTrackedYamlLoaderTests {
|
|||
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
|
||||
void unsupportedType() throws Exception {
|
||||
String yaml = "value: !!java.net.URL [!!java.lang.String [!!java.lang.StringBuilder [\"http://localhost:9000/\"]]]";
|
||||
|
|
|
@ -26,6 +26,8 @@ example:
|
|||
- bar2: bling
|
||||
empty: ""
|
||||
null-value: null
|
||||
emptylist: []
|
||||
emptymap: {}
|
||||
---
|
||||
|
||||
spring:
|
||||
|
|
Loading…
Reference in New Issue