java[CustomClassMapper]:没有用于。。。在Firebase Firestore的类中找到
我不知道为什么会有这样的警告:
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但在我的例子中,属性的名称和方法的名称是相同的
# 1 楼答案
您将收到以下警告:
因为
Liturgia
类中的lh
属性是Breviario
类型,而数据库中是字符串数组。两者必须匹配。因此,如果需要保留当前数据库数据,请将该属性更改为List<String>
类型除此之外,使用:
它是无用的,因为数据库中的属性已经被称为
lh
。所以没有这个必要编辑:
以下是解决整个问题的步骤:
lh
属性声明为HashMap<String, Object>
类型HashMap<String, Object>
HashMap<String, Object>
李>所以,这里是我的灵感来源:
对于二传手来说: