I have huge object, I have its class of course, I’m extracting some values from it, but since it is really big I don’t know in which list or where the value I’m looking for is.
Is there a way to create some kind of object breakdown routing and search every part for the value I’m expecting, and it is hidden somewhere in the object, I just can’t find it in Eclipse; it’s too nested.
I thought of using reflection to go through all fields of object class and search for the value inside of each field (fields inside lists (list of lists etc)). Any other ideas?
I assume you just want to find a specific value and to trace its source. And all this, you want to do at debug time. I would suggest two options.
Option1
Use JSON – Serialize the object to json string and do a manual text search on the result. You would neeed json.jar (or any other parser) for this.
Which will produce something like this. (I have simulated this by creating an object with some nested fields,lists,maps)
Option2
Convert/Serialize the object to XML. Use XStream for this,which will be the easiest of all available parsers. With just two lines of code,
Which will produce,
Either of the above approaches,you can either print the result to the console or to a file and inspect it manually.
Alternatively you can also use reflection,in which case you would have to write a lot of code and significant amount of time in testing it as well.