google / gson

A Java serialization/deserialization library to convert Java Objects into JSON and back
Apache License 2.0
23.13k stars 4.27k forks source link

Make com.google.gson.JsonElement Serializeable #2697

Closed AlexanderSchuetz97 closed 1 month ago

AlexanderSchuetz97 commented 1 month ago

Problem solved by the feature

I develop an Application that uses RMI for some internal communication. Objects passed via RMI from one part of the application to another need to implement Serializeable, otherwise it wont work. It would be most convienient for me to be able to pass JsonElement and its subclasses directly via RMI.

Feature description

Simply adding "implements Serializeable" to com.google.gson.JsonElement would solve my problem.

Alternatives / workarounds

Currently I have written a custom "String" wrapper class that is passed via RMI that indicates that the object is a json element. The side sending the object has to call JsonElement#toString while the receive side has to parse the JsonElement again. This is a bit cumbersome and needless in my opinion.

If you want to make it fancy.

You could implement java.io.Externalizable instead of Serializeable and write the data as Json over the RMI interface instead of using Javas Default Serialization facitilty. This would probably make it "faster", but require more effort compared to simply adding implements Serializeable to the class. For my use case this potencial performance gain is not required.

Marcono1234 commented 1 month ago

Sounds like a duplicate of #485, so I am closing this issue here. Cloneable has been implemented through the custom deepCopy() method, but Serializable hasn't yet.

I am not sure why this hasn't been implemented yet, but maybe one reason is that this involves more than just marking the classes Serializable, but you then also have to guarantee that their serialization format remains the same over time.