title: How to pretty print a complex Java object (e.g. with fields that are collections of objects)?
body: <p>I'm looking for a library function <em>(ideally from a commonly used framework e.g. Spring, Guava, Apache Commons etc.)</em> that will nicely print the values of any Java object.</p>
  
  <p>This is a general question rather than a specific one. Have seen similar questions on StackOverflow for which a common answer is "implement your own <code>toString()</code> method on the class" but this option isn't always practical - am looking for a general way of doing this with any object I come across, which may originate from third party code. Another suggestion is to use <a href="https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/builder/ReflectionToStringBuilder.html" rel="noreferrer">RefectionToStringBuilder</a> from Apache Commons, e.g:</p>
  
  <pre><code>new ReflectionToStringBuilder(complexObject, new RecursiveToStringStyle()).toString()
  </code></pre>
  
  <p>But this has limited use - e.g. when it comes across a collection it tends to output something like this:</p>
  
  <pre><code>java.util.ArrayList@fcc7ab1[size=1]
  </code></pre>
  
  <p>An actual use case example is to log an <a href="http://download.eclipse.org/jgit/docs/jgit-2.0.0.201206130900-r/apidocs/org/eclipse/jgit/transport/PushResult.html" rel="noreferrer"><code>Iterable&lt;PushResult&gt;</code></a> returned from JGit's <a href="http://download.eclipse.org/jgit/docs/jgit-2.0.0.201206130900-r/apidocs/org/eclipse/jgit/api/PushCommand.html#call()" rel="noreferrer"><code>pushCommand.call()</code></a> method - if posting an answer please make sure it would work with this as well as any other complex object.</p>