2忽略对象模型的新字段

2忽略对象模型的新字段

本文介绍了如何使用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:

查看依赖关系树,我得到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了。正确的注释是。

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

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

08-11 06:36