mirror of
https://github.com/lightbend/config.git
synced 2025-01-28 21:20:07 +08:00
Merge pull request #1 from typesafehub/list-of-beans
Fix compile/test for list of beans support
This commit is contained in:
commit
275f53c9ec
@ -170,7 +170,7 @@ public class ConfigBeanImpl {
|
||||
|
||||
private static Object getListValue(Class<?> beanClass, Type parameterType, Class<?> parameterClass, Config config, String configPropName) {
|
||||
Type elementType = ((ParameterizedType)parameterType).getActualTypeArguments()[0];
|
||||
|
||||
|
||||
if (elementType == Boolean.class) {
|
||||
return config.getBooleanList(configPropName);
|
||||
} else if (elementType == Integer.class) {
|
||||
@ -194,12 +194,12 @@ public class ConfigBeanImpl {
|
||||
} else if (elementType == ConfigValue.class) {
|
||||
return config.getList(configPropName);
|
||||
} else if (hasAtLeastOneBeanProperty((Class<?>) elementType)) {
|
||||
List<Object> beanList = new ArrayList<>();
|
||||
List<? extends Config> configList = config.getConfigList(configPropName);
|
||||
for (Config listMember : configList) {
|
||||
beanList.add(createInternal(listMember, (Class<?>) elementType));
|
||||
}
|
||||
return beanList;
|
||||
List<Object> beanList = new ArrayList<Object>();
|
||||
List<? extends Config> configList = config.getConfigList(configPropName);
|
||||
for (Config listMember : configList) {
|
||||
beanList.add(createInternal(listMember, (Class<?>) elementType));
|
||||
}
|
||||
return beanList;
|
||||
} else {
|
||||
throw new ConfigException.BadBean("Bean property '" + configPropName + "' of class " + beanClass.getName() + " has unsupported list element type " + elementType);
|
||||
}
|
||||
|
@ -128,12 +128,12 @@ public class ArraysConfig {
|
||||
public void setOfMemorySize(List<ConfigMemorySize> ofMemorySize) {
|
||||
this.ofMemorySize = ofMemorySize;
|
||||
}
|
||||
|
||||
|
||||
public List<StringsConfig> getOfStringBean() {
|
||||
return ofStringBean;
|
||||
}
|
||||
|
||||
return ofStringBean;
|
||||
}
|
||||
|
||||
public void setOfStringBean(List<StringsConfig> ofStringBean) {
|
||||
this.ofStringBean = ofStringBean;
|
||||
}
|
||||
this.ofStringBean = ofStringBean;
|
||||
}
|
||||
}
|
||||
|
@ -20,4 +20,26 @@ public class StringsConfig {
|
||||
public void setYes(String s) {
|
||||
yes = s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof StringsConfig) {
|
||||
StringsConfig sc = (StringsConfig) o;
|
||||
return sc.abcd.equals(abcd) &&
|
||||
sc.yes.equals(yes);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int h = 41 * (41 + abcd.hashCode());
|
||||
return h + yes.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StringsConfig(" + abcd + "," + yes + ")";
|
||||
}
|
||||
}
|
||||
|
@ -54,14 +54,14 @@
|
||||
"ofDuration" : [1, 2h, 3 days],
|
||||
"ofMemorySize" : [1024, 1M, 1G],
|
||||
"ofStringBean" : [
|
||||
{
|
||||
abcd : "testAbcdOne"
|
||||
yes : "testYesOne"
|
||||
},
|
||||
{
|
||||
abcd : "testAbcdTwo"
|
||||
yes : "testYesTwo"
|
||||
}
|
||||
{
|
||||
abcd : "testAbcdOne"
|
||||
yes : "testYesOne"
|
||||
},
|
||||
{
|
||||
abcd : "testAbcdTwo"
|
||||
yes : "testYesTwo"
|
||||
}
|
||||
]
|
||||
},
|
||||
"bytes" : {
|
||||
|
@ -46,10 +46,10 @@ class ConfigBeanFactoryTest extends TestUtils {
|
||||
ConfigBeanFactory.create(config, classOf[ValidationBeanConfig])
|
||||
}
|
||||
|
||||
val expecteds = Seq(Missing("propNotListedInConfig", 67, "string"),
|
||||
WrongType("shouldBeInt", 68, "number", "boolean"),
|
||||
WrongType("should-be-boolean", 69, "boolean", "number"),
|
||||
WrongType("should-be-list", 70, "list", "string"))
|
||||
val expecteds = Seq(Missing("propNotListedInConfig", 77, "string"),
|
||||
WrongType("shouldBeInt", 78, "number", "boolean"),
|
||||
WrongType("should-be-boolean", 79, "boolean", "number"),
|
||||
WrongType("should-be-list", 80, "list", "string"))
|
||||
|
||||
checkValidationException(e, expecteds)
|
||||
}
|
||||
@ -111,15 +111,15 @@ class ConfigBeanFactoryTest extends TestUtils {
|
||||
ConfigMemorySize.ofBytes(1048576),
|
||||
ConfigMemorySize.ofBytes(1073741824)),
|
||||
beanConfig.getOfMemorySize.asScala)
|
||||
|
||||
|
||||
val stringsConfigOne = new StringsConfig();
|
||||
stringsConfigOne.setAbcd("testAbcdOne")
|
||||
stringsConfigOne.setYes("testYesOne")
|
||||
val stringsConfigTwo = new StringsConfig();
|
||||
stringsConfigTwo.setAbcd("testAbcdTwo")
|
||||
stringsConfigTwo.setYes("testYesTwo")
|
||||
|
||||
assertEquals(List(stringsConfigOne, stringsConfigTwo), beanConfig.getOfStringBean)
|
||||
|
||||
assertEquals(List(stringsConfigOne, stringsConfigTwo).asJava, beanConfig.getOfStringBean)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user