我不知道为什么会收到此警告:
W/Firestore: (21.3.1) [CustomClassMapper]: No setter/field for
lh
. found on class com.example.model.Liturgia
获取数据代码:
DocumentReference calRef = db.collection(CALENDAR_PATH).document(fechaYY).collection(fechaMM).document(fechaDD);
calRef.addSnapshotListener((calSnapshot, e) -> {
if ((calSnapshot != null) && calSnapshot.exists()) {
mLiturgia = calSnapshot.toObject(Liturgia.class);
DocumentReference dataRef = calSnapshot.getDocumentReference("lh.1");
// ...
型号
public class Liturgia {
private Breviario lh;
//...
public Liturgia() {
}
@Exclude
public void getlh() {
}
@PropertyName("lh")
public void setLh(Breviario lh) {
this.lh = lh;
}
}
文件
(A):calRef
。
正如你在代码中看到的,首先我阅读了这个文档:
(B):calSnapshot
。
然后,在第二个实例中,我读取了 (A) 中 document
类型的一个字段中引用的另一个文档:
我将第二个文档映射到 Liturgia.class
。
如果我尝试将该方法命名为 set lh()
或尝试不使用 @PropertyName("lh")
,则始终会显示警告。
代码按预期工作,但我不想看到此警告。
我看到这个答案:W/Firestore: [CustomClassMapper]: No setter/field for class Android但就我而言,属性的名称和方法的名称是相同的。
最佳答案
您收到以下警告:
W/Firestore: (21.3.1) [CustomClassMapper]: No setter/field for lh found on class com.example.model.Liturgia
因为 lh
您的属性(property)Liturgia
类的类型为 Breviario
,而数据库中是一个字符串数组。两者必须匹配。因此,如果您需要保留当前数据库数据,请将该属性更改为 List<String>
类型。 .
除此之外,使用:
@PropertyName("lh")
没有用,因为数据库中的属性已经被称为 lh
。所以没有必要这样做。
编辑:
以下是解决整个问题的步骤:
- 声明
lh
属性类型为HashMap<String, Object>
- 删除@Ignore注释
- 更改 getter void 的返回类型以返回
HashMap<String, Object>
- 设置
HashMap<String, Object>
进入 setter 。
所以,这里是 setter/getter :
public HashMap<String, Object> getLh() {
return lh;
}
对于设置者:
public void setLh(HashMap<String, Object> lh) {
this.lh = lh;
}
关于java - [CustomClassMapper] : No setter/field for . .. 在 Firebase Firestore 中的类中找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61015574/