File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed
spring-boot-project/spring-boot/src
main/java/org/springframework/boot/env
java/org/springframework/boot/env
resources/org/springframework/boot/env Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 30
30
import org .yaml .snakeyaml .constructor .Constructor ;
31
31
import org .yaml .snakeyaml .constructor .SafeConstructor ;
32
32
import org .yaml .snakeyaml .error .Mark ;
33
+ import org .yaml .snakeyaml .nodes .CollectionNode ;
33
34
import org .yaml .snakeyaml .nodes .MappingNode ;
34
35
import org .yaml .snakeyaml .nodes .Node ;
35
36
import org .yaml .snakeyaml .nodes .NodeTuple ;
@@ -104,12 +105,15 @@ public Object getData() throws NoSuchElementException {
104
105
105
106
@ Override
106
107
protected Object constructObject (Node node ) {
108
+ if (node instanceof CollectionNode && ((CollectionNode <?>) node ).getValue ().isEmpty ()) {
109
+ return constructTrackedObject (node , super .constructObject (node ));
110
+ }
107
111
if (node instanceof ScalarNode ) {
108
112
if (!(node instanceof KeyScalarNode )) {
109
113
return constructTrackedObject (node , super .constructObject (node ));
110
114
}
111
115
}
112
- else if (node instanceof MappingNode ) {
116
+ if (node instanceof MappingNode ) {
113
117
replaceMappingNodeKeys ((MappingNode ) node );
114
118
}
115
119
return super .constructObject (node );
Original file line number Diff line number Diff line change 17
17
package org .springframework .boot .env ;
18
18
19
19
import java .nio .charset .StandardCharsets ;
20
+ import java .util .Collections ;
20
21
import java .util .List ;
21
22
import java .util .Map ;
22
23
@@ -120,6 +121,14 @@ void processEmptyAndNullValues() {
120
121
assertThat (getLocation (nullValue )).isEqualTo ("28:13" );
121
122
}
122
123
124
+ @ Test
125
+ void processEmptyListAndMap () {
126
+ OriginTrackedValue emptymap = getValue ("emptymap" );
127
+ OriginTrackedValue emptylist = getValue ("emptylist" );
128
+ assertThat (emptymap .getValue ()).isEqualTo (Collections .emptyMap ());
129
+ assertThat (emptylist .getValue ()).isEqualTo (Collections .emptyList ());
130
+ }
131
+
123
132
@ Test
124
133
void unsupportedType () throws Exception {
125
134
String yaml = "value: !!java.net.URL [!!java.lang.String [!!java.lang.StringBuilder [\" http://localhost:9000/\" ]]]" ;
Original file line number Diff line number Diff line change @@ -26,6 +26,8 @@ example:
26
26
- bar2 : bling
27
27
empty : " "
28
28
null-value : null
29
+ emptylist : []
30
+ emptymap : {}
29
31
---
30
32
31
33
spring :
You can’t perform that action at this time.
0 commit comments