android firebase错误在反序列化时期望一个List

时间:2017-05-12 11:19:42

标签: android json firebase arraylist hashmap

我见过类似的问题,但大多数人都尝试使用HashMap 列表并获取此错误。

从firebase检索数据时出错:

  

com.google.firebase.database.DatabaseException:在反序列化时期望一个List,但得到一个类java.util.HashMap

这是onDataChange:

@Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot a : dataSnapshot.getChildren()){
                mProducts.add(a.getValue(ProductTest.class));
            }
        }

我的ProductTest课程:

@IgnoreExtraProperties


public class ProductTest {

private long id;

@SerializedName("remote_id")
private long remoteId;
private long category;
private String code;
private String description;

@SerializedName("main_image")
private String mainImage;

@SerializedName("main_image_high_res")
private String mainImageHighRes;

private List<ProductVariantTest> variants;
private List<ProductTest> related;


public ProductTest() {
}

}

1 个答案:

答案 0 :(得分:0)

@IgnoreExtraProperties


public class ProductTest implements Serializable {

private long id;

@SerializedName("remote_id")
private long remoteId;
private long category;
private String code;
private String description;

@SerializedName("main_image")
private String mainImage;

@SerializedName("main_image_high_res")
private String mainImageHighRes;

private List<ProductVariantTest> variants;
private List<ProductTest> related;


public ProductTest() {
}

}


Try this one...