Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have to debug an issue which requires me to print all the values of a Value Object that is returned by a web service call. The Value object is a complex object in the sense, it has another object as its member which in turn has another object.

Printing all the values by using get methods is cumbersome. So I was wondering if there is a way to break down the value object by any way to get to a primitive level like String or int or Date and print them all using one API?

I had a look at the below question but my prob is that I don't have access to the source code of the value object. The sources are in obfuscated jar.

http://stackoverflow.com/questions/2413001/how-to-print-values-of-an-object-in-java

share|improve this question

closed as off topic by Stephen C, maple_shaft Nov 14 '12 at 9:47

Questions on Programmers Stack Exchange are expected to relate to software development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

You can use recursion to discover subfields structure

public static void dump(Object o){
    Field[] fields = ReflectUtils.getFields(o.getClass());
    try{
        for(Field field : fields){
            field.setAccessible(true);
            Object value = field.get(o);
            System.out.println(field.getName() + "=" + field.get(o));
        }
    }catch(Exception e){
        e.printStackTrace();
    }
}
share|improve this answer

You are looking for one of the Apache Commons utilites.

These do slightly different things depending on what you want to do with it.

share|improve this answer
    
+1 - ReflectionToStringBuilder does a really good job (generally) in these cases. –  Deco Nov 14 '12 at 1:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.