serialization - Serialize a Java object to Java code? -
is there implementation serialize java object java code? example, if have object
map<string,integer> m = new map<string,integer>(); m.put("foo",new integer(21)); i serialize using
objectoutputstream out = new objectoutputstream( ... ); out.writeobject( m ); out.flush(); and output would, example, be
java.util.map<string,integer> m = new java.util.map<string,integer>(); m.put("foo",new integer(21)); why want this? easier partially create complex objects programmatically , complete creation manually in code. code can included in source , version controlled else. note using external serialized objects not exceptable.
thanks can give.
i implemented functionality in new github project. can find project here:
https://github.com/manuelb/java-bean-to-code-serializer
the project not have external dependencies except junit.
currently not supporting arrays serialization yet. nevertheless there lot of functionalities:
object2codeobjectoutputstream object2codeobjectoutputstream = new object2codeobjectoutputstream( bytearrayoutputstream); object2codeobjectoutputstream.writeobject(<your-java-bean>); system.out.println( bytearrayoutputstream.tostring());
Comments
Post a Comment