File tree 3 files changed +34
-6
lines changed
main/java/org/springframework/beans/factory/config
test/java/org/springframework/beans/factory/config
3 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -293,10 +293,14 @@ else if (value instanceof Collection) {
293
293
// Need a compound key
294
294
@ SuppressWarnings ("unchecked" )
295
295
Collection <Object > collection = (Collection <Object >) value ;
296
- int count = 0 ;
297
- for (Object object : collection ) {
298
- buildFlattenedMap (result ,
299
- Collections .singletonMap ("[" + (count ++) + "]" , object ), key );
296
+ if (collection .isEmpty ()) {
297
+ result .put (key , "" );
298
+ } else {
299
+ int count = 0 ;
300
+ for (Object object : collection ) {
301
+ buildFlattenedMap (result , Collections .singletonMap (
302
+ "[" + (count ++) + "]" , object ), key );
303
+ }
300
304
}
301
305
}
302
306
else {
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
19
19
import java .io .IOException ;
20
20
import java .io .InputStream ;
21
21
import java .util .LinkedHashMap ;
22
+ import java .util .List ;
22
23
import java .util .Map ;
23
24
24
25
import org .junit .Test ;
@@ -116,6 +117,20 @@ public void testMapWithIntegerValue() throws Exception {
116
117
assertEquals (Integer .valueOf (3 ), sub .get ("key1.key2" ));
117
118
}
118
119
120
+ @ Test
121
+ public void mapWithEmptyArrayValue () {
122
+ this .factory .setResources (new ByteArrayResource ("a: alpha\n test: []" .getBytes ()));
123
+ assertTrue (this .factory .getObject ().containsKey ("test" ));
124
+ assertEquals (((List <?>)this .factory .getObject ().get ("test" )).size (), 0 );
125
+ }
126
+
127
+ @ Test
128
+ public void mapWithEmptyValue () {
129
+ this .factory .setResources (new ByteArrayResource ("a: alpha\n test:" .getBytes ()));
130
+ assertTrue (this .factory .getObject ().containsKey ("test" ));
131
+ assertNull (this .factory .getObject ().get ("test" ));
132
+ }
133
+
119
134
@ Test
120
135
public void testDuplicateKey () throws Exception {
121
136
this .factory .setResources (new ByteArrayResource ("mymap:\n foo: bar\n mymap:\n bar: foo" .getBytes ()));
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -207,6 +207,15 @@ public void testLoadNull() throws Exception {
207
207
assertThat (properties .getProperty ("spam" ), equalTo ("" ));
208
208
}
209
209
210
+ @ Test
211
+ public void testLoadEmptyArrayValue () {
212
+ YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean ();
213
+ factory .setResources (new ByteArrayResource ("a: alpha\n test: []" .getBytes ()));
214
+ Properties properties = factory .getObject ();
215
+ assertThat (properties .getProperty ("a" ), equalTo ("alpha" ));
216
+ assertThat (properties .getProperty ("test" ), equalTo ("" ));
217
+ }
218
+
210
219
@ Test
211
220
public void testLoadArrayOfString () throws Exception {
212
221
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean ();
You can’t perform that action at this time.
0 commit comments