Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

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.

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

You can use recursion to discover subfields structure

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

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