I tried to look at similar questions but they are of no use for me.
I have a class:
data class TextMessage(val text: String,
override
The problem in your code is that you are using a field named isText
. In Cloud Firestore the coresponding getter is getText()
and NOT getIsText()
as expected.
If you try to change the name of the field in, let's say, izText
instead of isText
and to have the corresponding getter like getIzText()
, your code will work perfectly fine. Firestore removes the is
prefix from the getter, that's why you have that conflict. For more informations, you can also take a look at this video.
If you decide to change that field name, don't forget to remove the old data and add fresh one.
The generated class file for TextMessage has the following methods defined. This was obtained by running javap against it:
public final java.lang.String getText();
public java.util.Date getTime();
public java.lang.String getSenderId();
public boolean isText();
The Firestore SDK is confused because it derives the names of document properties from the names of the getters in the class. So, by JavaBean convention, getText() becomes "text". And isText() also becomes "text". Firestore doesn't know which one you wanted to use for the document property called "text", hence the message.
You will have to change the name of one or the other to avoid this conflict. Alternately, you can try to use the PropertyName annotation to alter Firestore's naming of the field for either one.