I want to dynamically populate a java bean which has non primitive members, from a map.
By dynamically, I mean, I should be able to loop on the properties (as, the javabean type will be know at runtime) and set them based on key in the map.
I tried achieving the same using BeanUtilsBean.populate(), but it did not work.
For example, if the bean structure is as follows, I want to be able to populate Wrapper (its members) based on the map below the code snippet.
Key | Value
name | Tim
age | 29
faltNumber | 307
street | 78
city | NY
The API in the package java.beans can be used to access properties in Java beans. Start with class Introspector. It has getBeanInfo() methods which will give you a BeanInfo object, which has a method getPropertyDescriptors() that will give you a PropertyDescriptor for each of the bean's properties. The PropertyDescriptor contains methods to get the methods that you can call (via reflection) to read or write the bean property.
I have some code that allows you to view a Java Bean as a map. You could use it like this: