How to write the content of a Complex Java object to get rid of Cyclic and Redundant info

M

mullin

For example: (A simple case that Two objects with parent-child
relationship => 1 order has N order_allocs)

Orderes
========
orderId (String)
quantity (BigDecimal)
tradeDate (Date)

Order_Allocs
============
allocId (String)
allocQty (BigDecimal)
orderId (Set)

Though I can use ReflectionToStringBuilder.reflectionToString to write
and get rid of Cyclic issue, when writing the Order_Allocs object, it
will write back the information on Orders, so duplicate set of
information will be logged.

Any ideas to do so? Just want to write the debug messages.

Thanks!
 
R

Roedy Green

Though I can use ReflectionToStringBuilder.reflectionToString to write
and get rid of Cyclic issue, when writing the Order_Allocs object, it
will write back the information on Orders, so duplicate set of
information will be logged.

I would just put a boolean in each object initially false.
Then write a recursive method to chase the ordinary pointers you have
in your method, turning on the booleans as you start processing an
object after you finish you go. You add the addresses to an ArrayList
as you go. You return when or it is already marked an object as
processed.you have explored all the pointers out of an object. It is
much like traversing a tree. There is no need for reflection or aux
objects.
 

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,156
Latest member
KetoBurnSupplement
Top