I assume that you just want to find a specific value and trace its source. And all this, you want to do in debug time. I would suggest two options.
Option1 Use JSON . Serialize the object into a json string and do a manual search for the text by the result. You can use json.jar (or any other parser) for this.
try { System.out.println(new JSONObject(new YourHugeObject()).toString(5)); } catch (JSONException e) { log(e); }
Which will create something like that. (I mimicked this by creating an object with some nested fields, lists, maps)
{ "ct": { "a": 1, "b": "sdf", "f": 12, "nested": { "key1": { "kk": "kk", "ssdf": 123 }, "onemorekey": { "kk": "kk", "ssdf": 123 } } }, "doubleProp": 12.2, "lngprop": 1232323, "strProp": "123", "stringlist": [ "String1", "String2", "String3" ] }
Option2 Convert / Serialize the object to XML . Use XStream for this, which will be the easiest parser available. With just two lines of code,
XStream stream = new XStream(); System.out.println(stream.toXML(new YourHugeObject()));
What will produce
<com.kmg.jsontools.test.JSTest> <stringlist> <string>String1</string> <string>String2</string> <string>String3</string> </stringlist> <strProp>123</strProp> <doubleProp>12.2</doubleProp> <lngprop>1232323</lngprop> <ct> <a>1</a> <b>sdf</b> <f>12.0</f> <nested> <entry> <string>key1</string> <com.kmg.jsontools.test.Type1> <kk>kk</kk> <ssdf>123</ssdf> </com.kmg.jsontools.test.Type1> </entry> <entry> <string>onemorekey</string> <com.kmg.jsontools.test.Type1> <kk>kk</kk> <ssdf>123</ssdf> </com.kmg.jsontools.test.Type1> </entry> </nested> </ct> </com.kmg.jsontools.test.JSTest>
Any of the above approaches allows you to print the result on the console or in a file and check it manually. Alternatively, you can also use reflection, in which case you will have to write a lot of code and a significant amount of time when testing it.
chedine
source share