A. Cedano
A. Cedano

Reputation: 965

[CustomClassMapper]: No setter/field for ... found on class in Firebase Firestore

I don't know why I'm having this warning:

W/Firestore: (21.3.1) [CustomClassMapper]: No setter/field for lh. found on class com.example.model.Liturgia

Code for getting data:

    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");
            // ...

Model

public class Liturgia {
    private Breviario lh;
    //...

    public Liturgia() {
    }

    @Exclude
    public void getlh() {
    }

    @PropertyName("lh")
    public void setLh(Breviario lh) {
        this.lh = lh;
    }
}

Documents

(A): calRef.

As you can see in the code, first I read this document:

enter image description here

(B): calSnapshot.

And then, in the second instance, I read another document that is referred in one field of type document in (A):

enter image description here

And I map this second document to the Liturgia.class.

If I try to name the method as set lh() or I try without @PropertyName("lh") the warning shows always.

The code works as expected, but I don't want to see this warning.

I see this answer: W/Firestore: [CustomClassMapper]: No setter/field for class Android but in my case, the name of the property and the name of the method are the same.

Upvotes: 1

Views: 1883

Answers (1)

Alex Mamo
Alex Mamo

Reputation: 138924

You are getting the following warning:

W/Firestore: (21.3.1) [CustomClassMapper]: No setter/field for lh found on class com.example.model.Liturgia

Because the lh property in your Liturgia class is of type Breviario, while in the database is an array of Strings. Both must match. So if you need to keep the current database data, change that property to be of type List<String>.

Besides that, using:

@PropertyName("lh")

It is useless because the property in the database is already called lh. So there is no need for that.

Edit:

Here are the steps for solving the entire problem:

  1. Declare lh property to be of type HashMap<String, Object>
  2. Remove the @Ignore annotation
  3. Change the return type of the getter void to return the HashMap<String, Object>
  4. Set a HashMap<String, Object> into the setter.

So, here si the getter:

public HashMap<String, Object> getLh() {
    return lh;
}

And for the setter:

public void setLh(HashMap<String, Object> lh) {
    this.lh = lh;
}

Upvotes: 4

Related Questions