I have a collection of java bean objects and each object can have another collection of java bean objects (ie object graph). Is there an easy way to traverse the graph and call all the getter methods? Is there a library already doing something similar like that.
views:
77answers:
4
A:
You can use reflection to do so manually.
Also take look at common-beanutils, there might be something to help.
Dev er dev
2009-07-09 21:18:22
Using java.beans instead of java.reflect will handle all the beans conventions for you, and it's also a little safer.
Tom Hawtin - tackline
2009-07-09 21:28:31
+3
A:
Take a look at BeanInfo:
http://java.sun.com/j2se/1.4.2/docs/api/java/beans/BeanInfo.html
and especially the getPropertyDescriptors() method.
tputkonen
2009-07-09 21:23:30
+1
A:
java.beans.Introspector should allow you to traverse all the properties and methods of the beans.
nos
2009-07-09 21:24:41
A:
I have been using a library called FEST for some automated testing and it has a reflection library that works well for me.
Tony Eichelberger
2009-07-09 22:00:13