Is there an implementation that will serialize a Java object as Java code? For example, if I have the object
Map<String,Integer> m = new Map<String,Integer>();
m.put("foo",new Integer(21));
I could serialize this using
ObjectOutputStream out = new ObjectOutputStream( ... );
out.writeObject( m );
out.flush();
and the output would, for example, be
java.util.Map<String,Integer> m = new java.util.Map<String,Integer>();
m.put("foo",new Integer(21));
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.
Thanks for any help you can give.