question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for custom actions on annotations

See original GitHub issue
See the thread: 
http://groups.google.com/group/google-gson/browse_thread/thread/1ea949a5e50cc507

by supporting a custom action on an annotation, we will enable support for 
JPA/Hibernate and other kinds of annotations.

Original issue reported on code.google.com by inder123 on 26 Nov 2010 at 7:00

Issue Analytics

  • State:open
  • Created 9 years ago
  • Reactions:3
  • Comments:13

github_iconTop GitHub Comments

4reactions
amaksoftcommented, Jun 17, 2017

Hi, i want to share my implementation of custom annotation support for gson, which is backwards compatible: new interface ParametrizedTypeAdapterFactory extends TypeAdapterFactory and new method <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type, Annotation[] annotations) only gets called if field is annotated with specific annotation @Parametrized

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: https://github.com/amaksoft/gson/commit/b264334451c487d79241483103853c3fff27cbd4 Can you please review it?

3reactions
amaksoftcommented, Jun 18, 2017

Just wanted to explain my position: ParamterizedTypeAdapterFactory is just a special case of TypeAdapterFactory. In most cases Gson don’t even need to know that your factory accepts annotations. But in special cases like @CustomDateFormat on Date or @Id on int, you return a customized TypeAdapter only for this case, (we don’t cache it). No new lists of adapters needed, any of your existing TypeAdapters could be easily transformed into parametrized ones by implementing a new method.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Custom annotation tools with customized actions?
In my project we have a specific requirement of having customised tool. On tap it should add markers/location pins to the pdf at...
Read more >
5 Creating Custom Actions for Your APIs - Oracle Help Center
Simply put, you create a custom action by creating and compiling the Java code, adding it to externalactions, and then restarting the Services...
Read more >
Adding Custom Actions Using Extension Points - SAPUI5 SDK
In SAP Fiori elements for OData V4, footer bar actions are available only on the object page. These custom actions are displayed as...
Read more >
Custom Actions Overview - Frame.io Docs
Custom actions are a way for you to build integrations directly into Frame.io as programmable UI components. This page explains how they work....
Read more >
Enabling custom actions with a dialog for additional input fields
Actions with Parameters : In case a value help is added to an action parameter (e.g. via annotation @ValueHelpDefinition in corresponding ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found