如何使用Firebase 1.0.2忽略对象模型的新字段 [英] How to ignore new fields for an object model with Firebase 1.0.2

查看:153
本文介绍了如何使用Firebase 1.0.2忽略对象模型的新字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase依赖关系的目前的最新版本,这是1.0.2,我在解析我的pojos正确解析时遇到了问题。

I'm using the last version at the moment of Firebase dependency, which is 1.0.2 and I'm having problems into getting my pojos parsed correctly.

事情是,架构可以随时更改,但我不想要我的应用程序崩溃:

The thing is, at any time the schema can changed but I don't want my app to crash with this:


D / AndroidRuntime(14097):关闭VM W / dalvikvm(14097):
threadid = 1:线程退出,未捕获异常(组= 0x40a451f8)
E / AndroidRuntime(14097):致命异常:主
E / AndroidRuntime(14097):com.firebase.client.FirebaseException:失败
退回到E / AndroidRuntime(14097):
com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:213)

D/AndroidRuntime(14097): Shutting down VM W/dalvikvm(14097): threadid=1: thread exiting with uncaught exception (group=0x40a451f8) E/AndroidRuntime(14097): FATAL EXCEPTION: main E/AndroidRuntime(14097): com.firebase.client.FirebaseException: Failed to bounce to type E/AndroidRuntime(14097): at com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:213)

查看依赖关系树,我得到Firebase正在使用Jackson mapper 1.9.7,因此注释 @JsonIgnoreProperties(ignoreUnknown = true)是不是一个选择此外,对象映射器被包装到此Firebase对象中,因此我无法配置 DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES 属性( DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES

Looking into the dependency tree I get that Firebase is using Jackson mapper 1.9.7, so the annotation @JsonIgnoreProperties(ignoreUnknown = true") is not an option. Moreover, the object mapper is wrapped into this Firebase object so I can't configure the DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES property (DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES for Jackson 1.9 and before).

有没有办法设置这个属性,无论是作为类级注释还是配置映射器或任何其他机制无论如何?

Is there any way to set this property, either as a class-level annotation or configuring the mapper or any other mechanism whatsoever?

最好的解决方案是Firebase 1.0.3开始使用Jackson 2.0,但不知道这是否是他们现在关心的事情。

The best solution would be that Firebase 1.0.3 started using Jackson 2.0, but don't know if this is something they care about right now.

注意:我已经考虑过排除传递的Jackson 1.9.7依赖项并添加Jackson 2.0以便我可以访问这个ignoreUnknown功能,但我不认为它是一个可行的选择,因为我将更改市长版本。

Note: I've already thought about excluding the transitive Jackson 1.9.7 dependency and adding Jackson 2.0 so that I can access to this ignoreUnknown feature, but I don't think it is a viable choice since I would be changing the mayor version.

推荐答案

Firebase 1.0.3已发布,现在使用Jackson 2.2.2 ,所以注释 @JsonIgnore 是要走的路。

Firebase 1.0.3 was released and now uses Jackson 2.2.2, so annotation @JsonIgnore is the way to go.

编辑:截至2017年的
,Firebase不再使用Jackson了。正确的注释是 @Exclude

as of now in 2017, Firebase doesn't use Jackson anymore. the correct annotation is @Exclude.

这篇关于如何使用Firebase 1.0.2忽略对象模型的新字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆