0

Requirement: I need to dump the object graph of a Java application at various points of time during the application's execution. But most importantly, the dump needs to contain metadata for all objects in the graph e.g. the reference ids as obtained from System.identityHashCode(object).

What I tried: I found out serialization is a goto solution for obtaining the object graph.

I tried a couple of different solutions, including the built in Serialization facility in Java, JAXB and XStream. But I have no clue on how to get any of these libraries to spit out the objects' metadata such as the original reference IDs for the objects getting serialized.

Question: I was wondering if there was an easy way to include additional information/metadata about each object in an object graph that gets serialized?

While i am interested in specifically storing the objects' reference id, as obtained by System.identityHashCode(), any pointers on storing any data in general will be acceptable.

In case adding such metadata is not possible, that information will be useful as well.

NOTE: I ask this question despite the knowledge that the reference ids obtained from the System.identityHashCode() method are not required to be unique across different objects.

P.S. I am a newbie with Java serialization.

vijay
  • 2,646
  • 2
  • 23
  • 37
  • 1
    Of what use will the `identityHashCode` of an object be to you? There's no guarantee that it has any consistent semantics at different points in a JVM's execution. Read the Javadoc for `Object#hashCode()` -- there's no requirement that hash codes be unique. Also, since the usual implementation is the memory address, two different objects can have the same hashCode at different points in time without violating any contracts. – Jim Garrison Jul 03 '13 at 21:30
  • I get that there is no requirement that the hashcodes be unique. I am asking this question despite knowing that. If there is no way to add metadata to objects during their serialization, then knowing that would be useful as well. Thanks. – vijay Jul 03 '13 at 22:03
  • What is your *requirement?* – user207421 Jul 03 '13 at 23:45

0 Answers0