Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonSerializer/Deserializer: Allow reflection-oriented implementations #594

Open
GoogleCodeExporter opened this issue Mar 19, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

It would be nice to use the JsonSerializer interface (or something similar) on 
the class itself, rather than in a separate utility class which then needs to 
be registered as a type adapter.  In this manner, the interface would need to 
look like:

JsonElement serialize(JsonSerializationContext context)

, allowing the class to use the current object's state for serialization.  Gson 
could reflect prior to serializing and, if it implements this interface, 
delegate to it rather than do the normal class/field reflection.

A similar notion could be done for the deserialization side.  This would be 
similar to how Java serializable/externalizable mechanisms work.

Original issue reported on code.google.com by [email protected] on 2 Sep 2014 at 4:14

@Marcono1234
Copy link
Collaborator

With the com.google.gson.annotations.JsonAdapter annotation which was added in 2.3 (released 2014-08-11), this is already more convenient than having to register the adapters on the Gson instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants