如何使用getValue(Subclass.class)反序列化Firebase中的子类
我正在使用新的firebase sdk for android并使用真正的数据库功能。当我使用getValue(simple.class)一切都很好。但是,当我想解析一个子类的类时,母类的所有属性都是null,并且我有这种类型的错误:
在类uk.edume.edumeapp.TestChild上找不到名称的setter / field
public class TestChild extends TestMother {
private String childAttribute;
public String getChildAttribute() {
return childAttribute;
}}public class TestMother {
protected String motherAttribute;
protected String getMotherAttribute() {
return motherAttribute;
}}这个功能
snapshot.getValue(TestChild.class);
motherAttribute属性是null,我得到
在类uk.edume.edumeapp.TestChild上找不到motherAttribute的setter / field
我解析的Json是:
{
"childAttribute" : "attribute in child class",
"motherAttribute" : "attribute in mother class"}
ABOUTYOU
侃侃尔雅
明月笑刀无情
萧十郎
随时随地看视频慕课网APP