title: How can I serialize a (complex) doctrine 2 object?
body: <p>I am working with Doctrine2 (within Zend Framework, no Symfony2 around).</p>
  
  <p>I have a "complex" doctrine2 object which has a one-to-many relation with two other objects.</p>
  
  <p>The structure of my object looks like this:</p>
  
  <pre><code>   $object-&gt;attribute1 = "foo";
     $object-&gt;attribute2 = "bar";
     $object-&gt;doctrineCollection1 = &lt;DOCTRINE_COLLECTION2&gt;;
     $object-&gt;doctrineCollection1 = &lt;DOCTRINE_COLLECTION2&gt;;
  </code></pre>
  
  <p>I want to store it into Zend Cache somehow. What is the best way to serialize the complete object? I also tried to figure out how to encode it to JSON to get a hint, but wasn't successful yet.</p>