BeanUtils expects that your field names start with a lowercase letter, because it adheres to the JavaBean naming conventions.
In Section 8.8 of the JavaBeans spec:
Java programmers are accustomed to having normal identifiers start with lower case letters. Vigorous reviewer input has convinced us that we should follow this same conventional rule for property and event names.
Thus when we extract a property or event name from the middle of an existing Java name, we normally convert the first character to lower case. However to support the occasional use of all upper-case names, we check if the first two characters of the name are both upper case and if so leave it alone. So for example, “FooBah” becomes “fooBah” “Z” becomes “z” “URL” becomes “URL”
We provide a method Introspector.decapitalize which implements this conversion rule
That said, changing your code to this will fix it:
String value = BeanUtils.getNestedProperty(product, "prodClass.stbFlag");
If you are getting the string "StbFlag"
from an XML file, I would recommend using the same decapitalize
method that BeanUtils uses to convert it to the correct format.
Introspector.decapitalize("StbFlag")
which will return "stbFlag"
as a result.