Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you get a list of unrecognized JSON fields in Gson like Jackson's @JsonAnySetter?

So I currently use the Jackson parser and its libraries in my android projects. However, looking at the method counts for jackson and gson has me pondering about making a move to gson. After looking through different methods/syntax etc. I have been unable to find a gson equivalent to Jackson's @JsonAnySetter or @JsonAnyGetter.

Does this exist for gson? And if not, is there an work around?

like image 753
Breadbin Avatar asked Sep 30 '22 00:09

Breadbin


1 Answers

No, it doesn't. Gson basically has 2 commonly used annotations, @Expose and @SerializedName. To do what @JsonAnySetter and @JsonAnyGetter do, you'd have to write and register your own TypeAdapter that will group all fields that don't have a acorresponding Field and add them to a Map.

Jackson has so many more methods because it is a more complete API, with a larger feature set.

like image 171
Sotirios Delimanolis Avatar answered Oct 03 '22 01:10

Sotirios Delimanolis