Firebase Java对象序列化和继承 [英] Firebase java object serialization and Inheritance

查看:122
本文介绍了Firebase Java对象序列化和继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它是否也序列化继承的属性?

  @IgnoreExtraProperties 
公共类Item扩展BaseObservable {
私人字符串富;

public Item(){}

@Bindable
public String getFoo(){
return this.foo;



$ div $解析方案

刚刚遇到同样的问题,发现你的问题。虽然我在其他地方找不到明确的答案,但是一些实验表明, public 字段和getter都不被继承。



由于我的基类是抽象的,我只是将字段保护起来,并且实现了getter在每个子类中返回它们。重复是不理想的,但我的对象现在保存在Firebase的继承领域。


Does it also serialize inherited properties?

@IgnoreExtraProperties
public class Item extend BaseObservable {
    private String foo;

    public Item() { }

    @Bindable
    public String getFoo() {
        return this.foo;
    }
}

解决方案

I just ran into the same issue and found your question. While I could not find a definitive answer elsewhere, some experimentation revealed that neither public fields nor getters are inherited.

Since my base class is abstract, I just made the fields protected and implemented getters to return them in each subclass. The repetition isn't ideal, but my objects are now saving in Firebase with the inherited fields.

这篇关于Firebase Java对象序列化和继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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