This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes iterate to all List type property of my objects recursively Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "iterate to all List type property of my objects recursively" Watch "iterate to all List type property of my objects recursively" New topic
Author

iterate to all List type property of my objects recursively

Jay Richards
Ranch Hand

Joined: Jan 16, 2003
Posts: 58
Hi,

maybe some expert in reflection can help me with my problem.

i need a way to access a List property on my object, but this must also recursively parse any List property it may find on the List Object.

just a simple traversing with system.out will do. please help. thanks.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Look into reflection, ie using the methods on the Class class. Look at the JavaDoc for Class getFields() and getDeclaredFields(). Many frameworks that convert objects to XML or move objects in and out of databases use these tricks to get and set fields. Take a shot at making them work from the doc and let us know how it goes!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jay Richards
Ranch Hand

Joined: Jan 16, 2003
Posts: 58
hi, just wanna share

listing the properties of a class and checking if its a list was easy



ReflectionUtils


just posted my code just in case someone needs a similar approach.

hth,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: iterate to all List type property of my objects recursively
 
Similar Threads
Print String
recursive tree
Recursive Reflection method
how to add every entry into a List as an Object
MarshallingHttpMessageConverter - How to validate Input Data