简体   繁体   English

如何获得Gson中无法识别的JSON字段的列表,例如Jackson的@JsonAnySetter?

[英]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.

相关问题 Jackson Json 和 @JsonAnySetter 的不稳定行为 - Unstable behavior with Jackson Json and @JsonAnySetter 使用 Jackson,如何从有趣的 json 中获取对象列表? - Using Jackson, how can you get a list of objects from an interesting json? 使用@JsonAnySetter映射jackson返回javassist类的无法识别的字段 - mapping jackson with @JsonAnySetter returns Unrecognized field with javassist class 你如何通过Jackson的JsonGenerator编写原始JSON? - How can you write raw JSON through Jackson's JsonGenerator? 如何在 GSON 中获取 json 数据中的附加字段 - How to get additional fields in a json data in GSON Jackson:如何使用带有@JsonAnySetter 注释的自定义解串器? - Jackson: How to use a custom deserializer with @JsonAnySetter annotation? 使用 @JsonAnyGetter /@JsonAnySetter 序列化 JSON 并更改属性名称 (Jackson) - Using @JsonAnyGetter /@JsonAnySetter to Serialize JSON and change property name (Jackson) 如何将 Jackson PrettyPrinter 格式的 json 配置为 Gson - How to configure Jackson PrettyPrinter format json as Gson 用Jackson进行反序列化:获取Json对象设置的字段列表 - deserialization with Jackson: get list of fields set by Json object 使用 Gson 或 Jackson 反序列化 JSON 时忽略空字段 - Ignore null fields when DEserializing JSON with Gson or Jackson
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM