【问题标题】:android firebase error expected a List while deserializingandroid firebase错误在反序列化时需要一个列表
【发布时间】:2017-10-11 16:54:29
【问题描述】:

我见过类似的问题,但他们中的大多数都尝试使用 HashMap 来代替 List 并得到这个错误。

从 firebase 检索数据时出错:

com.google.firebase.database.DatabaseException:反序列化时需要一个列表,但得到一个类 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() {
}

}

【问题讨论】:

    标签: android json firebase arraylist hashmap


    【解决方案1】:
    @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...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-24
      • 2017-10-17
      • 2021-07-08
      • 2020-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多