mirror of
https://github.com/lightbend/config.git
synced 2025-01-28 21:20:07 +08:00
Fix for issue #447. Ignore bean properties without a proper setter/getter
This commit is contained in:
parent
01bb93367f
commit
4d98a0069e
@ -69,7 +69,9 @@ public class ConfigBeanImpl {
|
||||
try {
|
||||
List<PropertyDescriptor> beanProps = new ArrayList<PropertyDescriptor>();
|
||||
for (PropertyDescriptor beanProp : beanInfo.getPropertyDescriptors()) {
|
||||
if (beanProp.getReadMethod() == null || beanProp.getWriteMethod() == null) {
|
||||
if (beanProp.getReadMethod() == null
|
||||
|| beanProp.getWriteMethod() == null
|
||||
|| getField(clazz, beanProp.getName()) == null) {
|
||||
continue;
|
||||
}
|
||||
beanProps.add(beanProp);
|
||||
|
@ -0,0 +1,24 @@
|
||||
package beanconfig;
|
||||
|
||||
public class DifferentFieldNameFromAccessorsConfig {
|
||||
|
||||
private String customStringField;
|
||||
private Long number;
|
||||
|
||||
|
||||
public String getStringField() {
|
||||
return customStringField;
|
||||
}
|
||||
|
||||
public void setStringField(String stringField) {
|
||||
this.customStringField = stringField;
|
||||
}
|
||||
|
||||
public Long getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(Long number) {
|
||||
this.number = number;
|
||||
}
|
||||
}
|
@ -237,6 +237,14 @@ class ConfigBeanFactoryTest extends TestUtils {
|
||||
assertTrue("error about the right property", e.getMessage.contains("'map'"))
|
||||
}
|
||||
|
||||
@Test
|
||||
def testDifferentFieldNameFromAccessors(): Unit = {
|
||||
val e = intercept[ConfigException.ValidationFailed] {
|
||||
ConfigBeanFactory.create(ConfigFactory.empty(), classOf[DifferentFieldNameFromAccessorsConfig])
|
||||
}
|
||||
assertTrue("only one missing value error", e.getMessage.contains("No setting"))
|
||||
}
|
||||
|
||||
private def loadConfig(): Config = {
|
||||
val configIs: InputStream = this.getClass().getClassLoader().getResourceAsStream("beanconfig/beanconfig01.conf")
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user