[英]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. 所以我目前在我的android项目中使用Jackson解析器及其库。 However, looking at the method counts for jackson and gson has me pondering about making a move to gson. 但是,查看jackson和gson的方法计数让我思考着要转向gson。 After looking through different methods/syntax etc. I have been unable to find a gson equivalent to Jackson's @JsonAnySetter or @JsonAnyGetter. 在查看了不同的方法/语法等之后,我一直找不到与杰克逊的@JsonAnySetter或@JsonAnyGetter等效的gson。
Does this exist for gson? gson是否存在? And if not, is there an work around? 如果没有,是否可以解决?
No, it doesn't. 不,不是。 Gson basically has 2 commonly used annotations, @Expose
and @SerializedName
. Gson基本上有2个常用注释, @Expose
和@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
. 要执行@JsonAnySetter
和@JsonAnyGetter
操作,您必须编写并注册自己的TypeAdapter
,该TypeAdapter
将所有没有对应Field
归为一组并将其添加到Map
。
Jackson has so many more methods because it is a more complete API, with a larger feature set. Jackson具有更多的方法,因为它是一个更完整的API,具有更大的功能集。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.