Android @PropertyName与Firestore在Kotlin中不起作用

Android @PropertyName与Firestore在Kotlin中不起作用,android,firebase,kotlin,serialization,google-cloud-firestore,Android,Firebase,Kotlin,Serialization,Google Cloud Firestore,我对Firestore有一些问题,因为@PropertyName在数据类中被完全忽略 import com.google.firebase.database.PropertyName data class Profile( @get:PropertyName("player_uuid") @set:PropertyName("player_uuid") @PropertyName("player_uuid"

我对Firestore有一些问题,因为@PropertyName在数据类中被完全忽略

import com.google.firebase.database.PropertyName




data class Profile(
    @get:PropertyName("player_uuid")
    @set:PropertyName("player_uuid")
    @PropertyName("player_uuid")
    var playerUuid: String? = null,
   }
我已经尝试了所有注释的组合,但它们似乎都不起作用,因为当我从服务器获取播放器Uuid时,它总是为空

如何解析对象-

FirebaseFirestore.getInstance().document("profile/$id").get().await().toObject(Profile::class.java)
设置文档时也会发生同样的情况

FirebaseFirestore.getInstance().document("profile/$id").set(profile).await()

在firebase控制台上,我将发送playeruid而不是player_uuid。

您必须将@Keep添加到您的类中。或者Proguard将重命名变量 如果字段名是变量名,请检入firestore datatabase

@Keep
data class Profile(
@get:PropertyName("player_uuid")
@set:PropertyName("player_uuid")
var playerUuid: String? = null)

您对Firestore使用了错误的导入。您现在使用的是实时数据库。改用。

我没有使用proguard。请编辑问题以显示添加的导入@PropertyName@DougStevensondoneAnd仅仅是PropertyName就足够了,或者我必须同时提供get:和set:注释?我不记得曾经使用过get和set,但是,我可能只是在使用PropertyName时才使用Java。那是几年前的事了。在Java中,我认为您只需要注释getter。