google/gson

Let JsonElement implement Cloneable and Serializable

Opened this issue · 5 comments

the gson API is neither Serializable nor Cloneable. I'd imagine that both 
features should be relatively easy to implement...?

Original issue reported on code.google.com by lukas.eder@gmail.com on 8 Nov 2012 at 3:51

We have JsonElement.deepCopy() but it isn't yet public.

Original comment by limpbizkit on 4 Feb 2013 at 3:56

Is Serializable still going to be implemented? 🎱

JsonElement.deepCopy() is public since 2.8.2; now for that Serialization.

Pull request: #1178

It is really odd that Serialzeable has not been implemented. It is trivial to implement it if one does not care that the serialization format may change over time. (This would be fine for my use case of RMI where I can guarantee that all readers/writers will have the same version of Gson)

It is also quite simple to implement it using "Externalizeable". This gives you full control over the serialization. You could essentially just call JsonParser.parse in the read method and toString (or its into stream equivalent) in the write method.
This would guarantee the encapsulated data to be stored as Json and thus be parseable by any version of Gson.

I would be willing to put the time and effort together to properly implement the Externalizeable proposal if there is a chance of it getting merged. Since this issue is almost 10 years old I am not sure if investing my time into this would be worth it.