Serialize a Java object to Java code?

后端 未结 5 2096
轻奢々
轻奢々 2020-12-31 14:03

Is there an implementation that will serialize a Java object as Java code? For example, if I have the object

Map m = new Map

        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-31 14:42

    I implemented this functionality in a new github project. You can find the project here:

    https://github.com/ManuelB/java-bean-to-code-serializer

    The project does not have any external dependencies except junit.

    Currently it is not supporting arrays for serialization yet. Nevertheless there is already a lot of functionalities:

            Object2CodeObjectOutputStream object2CodeObjectOutputStream = new Object2CodeObjectOutputStream(
                byteArrayOutputStream);
            object2CodeObjectOutputStream.writeObject();
            System.out.println(
                    byteArrayOutputStream.toString());
    

提交回复
热议问题