Firebase java object serialization and Inheritance [duplicate]

故事扮演 提交于 2019-12-30 09:54:11

问题


Does it also serialize inherited properties?

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

    public Item() { }

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

回答1:


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.



来源:https://stackoverflow.com/questions/37331293/firebase-java-object-serialization-and-inheritance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!