-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add support for custom actions on annotations #269
Comments
Exactly the same need here. Another reason: if I made a commit to my fork for a quick review on the idea. @inder123 will you please review this? |
Hi, i want to share my implementation of custom annotation support for gson, which is backwards compatible: I mostly wanted it for serializing some dates by specifying custom pattern in annotation like this: class Person {
@Expose
@SerializedName("birth_date")
@Parametrized
@CustomDateFormat("MMMM d, yyyy h:mm:ss a z")
private Date birthDate;
} Here is a draft implementation: |
Just wanted to explain my position: |
@amaksoft Why this is not yet accepted? Jeezus.
|
Anyway this can be added without hacking google gson library ? |
Another approach could be to extend Gson's
|
Thanks, @Marcono1234, for the detailed analysis! I think it is only fair to say at the outset that this is probably too big a change to envisage given that we are technically in maintenance mode. If we were going to do something, there is a further complication. This issue was originally filed in 2010, no less. In the meantime, Java 8 added type annotations in 2014. Customizing serialization and deserialization based on type annotations seems a lot more logical than customizing based on annotations that happen to be on the field that is being serialized or deserialized. The API change to support just type annotations might be as simple as adding these to ...
import java.lang.reflect.AnnotatedType;
...
public class TypeToken<T> {
...
public static TypeToken<?> get(AnnotatedType type) {...}
...
public AnnotatedType getAnnotatedType() {...}
...
} But that has similar problems to the ones @Marcono1234 notes. Gson serializes and deserializes a field by extracting its type as a (We would also need to drop Java 7 compatibility and specify a minimum of Java 8, but we've been thinking about doing that anyway. I think ten years is enough time for client code to move to a Java platform.) |
Original issue reported on code.google.com by
inder123
on 26 Nov 2010 at 7:00The text was updated successfully, but these errors were encountered: