Search code examples
javaconstructorxstream

Debug XStream with no default constructor


I am trying to deserialize a XML using XStream. In there I have object A which does not have a default constructor. Then there is object B that references object A. At that point A is instantiated, but all fields are null, even though the values are defined in the XML.

My question is: How can I debug the instantiation of object A?


Solution

  • Any easy way to hook into the unserializing is to put a break point in the TreeUnmarshaller's convert method where convertAnother is called. There you can make the breakpoint on the condition the right type is hit, in my case A. Going down I endend up in SunLimitedUnsafeReflectionProvider.newInstance where a new instance is allocated using sun.misc.Unsafe.