mirror of
https://github.com/lightbend/config.git
synced 2025-03-22 23:30:27 +08:00
An empty string config value is now converted to an empty list when asking for a list.
This commit is contained in:
parent
09146706db
commit
909b11854b
@ -48,7 +48,12 @@ final class DefaultTransformer {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case LIST:
|
case LIST:
|
||||||
// can't go STRING to LIST automatically
|
// can't go STRING to LIST automatically unless the string is empty
|
||||||
|
if (s.equals("")) {
|
||||||
|
// Convert empty string to empty list
|
||||||
|
ArrayList<AbstractConfigValue> emptyList = new ArrayList<AbstractConfigValue>();
|
||||||
|
return new SimpleConfigList(value.origin(), emptyList);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case OBJECT:
|
case OBJECT:
|
||||||
// can't go STRING to OBJECT automatically
|
// can't go STRING to OBJECT automatically
|
||||||
|
@ -838,7 +838,8 @@ final class SimpleConfig implements Config, MergeableValue, Serializable {
|
|||||||
}
|
}
|
||||||
} else if (referenceType == ConfigValueType.LIST) {
|
} else if (referenceType == ConfigValueType.LIST) {
|
||||||
// objects may be convertible to lists if they have numeric keys
|
// objects may be convertible to lists if they have numeric keys
|
||||||
if (value instanceof SimpleConfigList || value instanceof SimpleConfigObject) {
|
// empty strings may also be converted to lists
|
||||||
|
if (value instanceof SimpleConfigList || value instanceof SimpleConfigObject || value instanceof ConfigString) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -26,7 +26,8 @@
|
|||||||
"true" : "true",
|
"true" : "true",
|
||||||
"yes" : "yes",
|
"yes" : "yes",
|
||||||
"false" : "false",
|
"false" : "false",
|
||||||
"no" : "no"
|
"no" : "no",
|
||||||
|
"empty": ""
|
||||||
},
|
},
|
||||||
|
|
||||||
"arrays" : {
|
"arrays" : {
|
||||||
|
@ -588,6 +588,18 @@ class ConfigTest extends TestUtils {
|
|||||||
assertEquals(Seq(), conf.getBooleanList("arrays.empty").asScala)
|
assertEquals(Seq(), conf.getBooleanList("arrays.empty").asScala)
|
||||||
assertEquals(Seq(), conf.getNumberList("arrays.empty").asScala)
|
assertEquals(Seq(), conf.getNumberList("arrays.empty").asScala)
|
||||||
assertEquals(Seq(), conf.getList("arrays.empty").asScala)
|
assertEquals(Seq(), conf.getList("arrays.empty").asScala)
|
||||||
|
|
||||||
|
// get empty array from empty string as any type of array
|
||||||
|
assertEquals(Seq(), conf.getAnyRefList("strings.empty").asScala)
|
||||||
|
assertEquals(Seq(), conf.getIntList("strings.empty").asScala)
|
||||||
|
assertEquals(Seq(), conf.getLongList("strings.empty").asScala)
|
||||||
|
assertEquals(Seq(), conf.getStringList("strings.empty").asScala)
|
||||||
|
assertEquals(Seq(), conf.getLongList("strings.empty").asScala)
|
||||||
|
assertEquals(Seq(), conf.getDoubleList("strings.empty").asScala)
|
||||||
|
assertEquals(Seq(), conf.getObjectList("strings.empty").asScala)
|
||||||
|
assertEquals(Seq(), conf.getBooleanList("strings.empty").asScala)
|
||||||
|
assertEquals(Seq(), conf.getNumberList("strings.empty").asScala)
|
||||||
|
assertEquals(Seq(), conf.getList("strings.empty").asScala)
|
||||||
|
|
||||||
// get typed arrays
|
// get typed arrays
|
||||||
assertEquals(Seq(1, 2, 3), conf.getIntList("arrays.ofInt").asScala)
|
assertEquals(Seq(1, 2, 3), conf.getIntList("arrays.ofInt").asScala)
|
||||||
|
Loading…
Reference in New Issue
Block a user