title: Serialize a Java object to Java code?
body: <p>Is there an implementation that will serialize a Java object as Java code? For example, if I have the object</p>
  
  <pre><code>Map&lt;String,Integer&gt; m = new Map&lt;String,Integer&gt;();
  m.put("foo",new Integer(21));
  </code></pre>
  
  <p>I could serialize this using</p>
  
  <pre><code>ObjectOutputStream out = new ObjectOutputStream( ... );
  out.writeObject( m );
  out.flush();
  </code></pre>
  
  <p>and the output would, for example, be</p>
  
  <pre><code>java.util.Map&lt;String,Integer&gt; m = new java.util.Map&lt;String,Integer&gt;(); 
  m.put("foo",new Integer(21));
  </code></pre>
  
  <p>Why would you want this? Sometimes it is easier to partially create complex objects programmatically and then complete the creation manually in code. This code can then be included in the source and version controlled with everything else. Note that using external serialized objects is not exceptable.</p>
  
  <p>Thanks for any help you can give.</p>