Subdivision objects in Java
I have a huge object. Of course I have its class. I extract some values from it, but because it's really big, I don't know which list or what value I'm looking for
Is there any way to create an object decomposition route and search for the expected value of each part? It is hidden somewhere in the object. I just can't find it in eclipse. It's too nested
I thought about using reflection to traverse all fields of the object class and search for values in each field (fields in the list (list, etc.)) Any other ideas?
Unfortunately, none of these answers helped me. I'm starting to reward
Solution
I assume you just want to find a specific value and track its source And all this, you want to do when debugging I suggest two options
Option 1 uses JSON – serializes objects into JSON strings and performs a manual text search on the results You need JSON Jar (or any other parser)
try { System.out.println(new JSONObject(new YourHugeObject()).toString(5)); } catch (JSONException e) { log(e); }
Which would produce such a thing I simulate this by creating an object with some nested fields, lists, and 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" ] }
Option 2 converts / serializes the object to XML Using xStream, this will be the simplest of all available parsers Just two lines of code,
XStream stream = new XStream(); System.out.println(stream.toXML(new YourHugeObject()));
Which 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>
Either way, you can print the results to the console or file and check them manually Alternatively, you can use reflection, in which case you have to write a lot of code and spend a lot of time testing