java - 如何在 Firestore 文档中获取嵌套对象?
问题描述
我的文档设计如下:
Document[IgaSZRSo8viqK9VxpJ6H]:
name:David
type:1
proList:
item1:
name:apple
price:1
item2:
name:grape
price:1
item3:
name:orange
price:2
amount:
basic:10
extra:20
上传到firestore时一切顺利,但是当我从firestore下载日期时,当我输入以下内容时,我总是收到异常“java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法”: proList.item1.name
我可以得到所有信息,包括amount.basic和amount.extra没有任何错误!
我不知道为什么,也无法在官方文档中找到任何信息。
编辑
以下是Java中的结构:
任务实体.java:
public class TaskEntity{
public String name, type;
public proListEntity;
public amountEntity;
public TaskEntity(){
}
public void set(TaskEntity entity){
this.name=entity.name;
this.type=entity.type;
this.proListEntity=entity.proListEntity;
this.amountEntity=entity.amountEntity;
}
}
proListEntity.java
public class proListEntity{
public String name;
public long price;
public proListEntity(){
}
public void set(proListEntity entity){
this.name=entity.name;
this.price=entity.price;
}
}
从 Firestore 下载数据:
TaskEntity mEntity = documentSnapshot.toObject(TaskEntity.class);
解决方案
推荐阅读
- javascript - 如何在 ASP.NET 网站上通过 ID 限制网站/链接访问?
- c++ - 二维动态数组逻辑
- css - 如何创建具有不同颜色的左上角和右下角边框?
- python - python中的多变量优化
- python-3.x - 如何用字典中的值替换数据框系列/列中的旧字符串值?
- shell - 'adb shell' 这两个壳是链式的吗?
- ios - iOS:将 Braintree 返回的 UIView 添加到屏幕
- angular-material - 我需要导入哪些指令才能使用材料列表项?
- excel-formula - 如何根据列中的值从列表中选择值
- apache-spark - Spark 输出 JSON 与 Parquet 文件大小差异