• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamically populate java bean tree

 
Amar Jee
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic