I have a Product class:
public class Product {
private ProductClass prodClass;
public ProductClass getProdClass() {
return prodClass;
}
public void setProdClass(ProductClass prodClass) {
this.prodClass = prodClass;
}
}
And another one ProductClass ...
public class ProductClass {
private String StbFlag;
public String getStbFlag() {
return StbFlag;
}
public void setStbFlag(String stbFlag) {
StbFlag = stbFlag;
}
}
When I try to get the Property using BeanUtils.getNestedProperty as shown below..
public class Test {
public static void main(String Args[]) {
Product product = new Product();
ProductClass proClass = new ProductClass();
proClass.setStbFlag("abcd");
product.setProdClass(proClass);
try {
String value = BeanUtils.getNestedProperty(product, "prodClass.StbFlag");
System.out.println(value);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Its throwing the following exception...
java.lang.NoSuchMethodException: Unknown property 'StbFlag' on class 'class ProductClass'
at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1313)
at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:762)
at org.apache.commons.beanutils.BeanUtilsBean.getNestedProperty(BeanUtilsBean.java:715)
at org.apache.commons.beanutils.BeanUtils.getNestedProperty(BeanUtils.java:354)
at Test.main(Test.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
What could be the reason? This is just a sample I used to find out the problem. I am actually mapping XML to Java Object and need to keep the name as StbFlag as per the xml tag.
It's working fine when I use STBflag or stbFlag as the variable name. Any workaround for this?