Firestore排除数据序列化 [英] Firestore exclude data serialization

查看:50
本文介绍了Firestore排除数据序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些不应该转移到Firestore的属性,例如元数据("id"或"parent"),并且在Firebase Realtime数据库中,可以选择将它们设置为protected并使其成为getter使外界可以访问它们,但不能序列化到Firebase.

I've got several properties that should not be transferred to Firestore, such as metadata ("id" or "parent"), and with Firebase Realtime database, there was the option to set them to protected and make a getter to make them accessible to the outside world but not serialize to Firebase.

使用Firestore防止属性序列化的唯一选择是创建一个具有私有属性的类并对其进行扩展.但这并不是真正有用的,因为甚至无法从类内部访问该属性.

With Firestore the only option to prevent a property from serialization is to create a class with a private property and extend that. But this is not really useful as the property is not even accessible from inside the class.

您能帮我找到创建不序列化到Firestore的类属性的解决方案吗? (也许是注释?)

Can you help me find a solution to create class properties that don't serialize to Firestore? (Maybe annotations?)

任何帮助将不胜感激!

推荐答案

要将字段标记为从Firestore或Realtime数据库中排除,您可以使用

To mark a field as excluded from the Firestore or Realtime database you can use the @Exclude annotation. For example:

@IgnoreExtraProperties
public class Model {
    @Exclude private String id;

    // ...
}

您还可以针对该类使用 @IgnoreExtraProperties 批注自动忽略不映射到类字段的属性.

You can also use the @IgnoreExtraProperties annotation against the class to automatically ignore properties that don't map to class fields.

这篇关于Firestore排除数据序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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