Recursively collecting object fields

D

dhina.jayavelu

Is there any algorithm to recursively collect object fields during the
runtime in java using
reflection mechanism. The process is similar to object serialization in
java. if the object contains a field which is an object , i have to
collect the fields of inner object also.

by

Dhinakaran
 
?

=?ISO-8859-15?Q?R=E9mi?= Bastide

Is there any algorithm to recursively collect object fields during the
runtime in java using
reflection mechanism. The process is similar to object serialization in
java. if the object contains a field which is an object , i have to
collect the fields of inner object also.

I guess this is basically what XMLEncoder does:
http://java.sun.com/j2se/1.4.2/docs/api/java/beans/XMLEncoder.html

You get an XML serialization (recursive) of your object, you can do whatever
you want with it afterwards.
 
S

Stefan Schulz

There is, since serialization does work. ;-P

You could view your classes as nodes on a graph, with fields being the
edges connecting them. To find all fields, do a DFS or BFS on the
graph. It will eventually visit all nodes, and thereby encounter all
edges (fields). Just add the fields of each node you visit to some data
structure as you go along.
 
D

dhina.jayavelu

Stefan said:
There is, since serialization does work. ;-P

You could view your classes as nodes on a graph, with fields being the
edges connecting them. To find all fields, do a DFS or BFS on the
graph. It will eventually visit all nodes, and thereby encounter all
edges (fields). Just add the fields of each node you visit to some data
structure as you go along.

Is there any open source code available for doing Traversal. Kindly
notice me.

by
Dhinakaran
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top