gpt4 book ai didi

java - Firebase Firestore 分布式计数器 - 找不到要序列化的属性

转载 作者:行者123 更新时间:2023-12-02 10:52:40 25 4
gpt4 key购买 nike

我已经根据此 post 中的建议阅读并更改了我的代码.

但是,我的问题仍然存在,出现相同的错误:

java.lang.RuntimeException: No properties to serialize found on class com.blush.android.blush.chat.chatCloudCommunications.ChatCloudSentMessageToFirestore$Counter

我正在一个名为 ChatCloudSentMessageToFirestore 的公共(public)类中运行下面的所有内容。我省略了在同一个类中定义的“createCounter”、“getCounter”和“incrementCounter”。我这样做是为了保持代码简短,并且因为它们与 Firebase Firestore 网站上定义的内容相同:https://firebase.google.com/docs/firestore/solutions/counters所以不太可能是错误的原因(除非它们需要我不知道的任何修改)。

public class Counter {
int numShards;

public Counter(int numShards) {
this.numShards = numShards;
}
}

// counters/${ID}/shards/${NUM}
public static class Shard {
int count;

public Shard(){}

public Shard(int count) {
this.count = count;
}
}

我在同一类中也有此引用:

DocumentReference counterChrisDocRef = db.collection("users")
.document("ypiXrobQxuZ0wplN5KO8gJf934")
.collection("conversations")
.document("conversation0") //Specified conversation
.collection("messageCounter")
.document("shards");

我正在尝试在此方法中使用计数器:

public void addSentMessageToFirestoreDB(final Map<String, Object> messageSent) {
WriteBatch batch = db.batch();

createCounter(counterChrisDocRef, 1);

incrementCounter(counterChrisDocRef, 1);


DocumentReference chrisSentMessageRef = db.collection("users")
.document("ypiXrobQxuZ0wplN5KO8gJf934")
.collection("conversations")
.document("conversation0") //Specified conversation
.collection("messages")
.document("message" + getCount(counterChrisDocRef) + " (sent)");

batch.set(chrisSentMessageRef, messageSent);

batch.commit().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {

}
});

最佳答案

由于您根本没有对类中的字段使用公共(public) getter,因此请将所有字段设置为 public,因为您的代码中的字段现在都是默认字段。为了直接在您的字段上设置值,您的字段必须是公共(public)。如果您想将字段设为私有(private),只需添加相应的公共(public) getter 即可,一切都会正常工作。

另请从您的 Shard 类中删除 static 关键字。无需使该类静态

关于java - Firebase Firestore 分布式计数器 - 找不到要序列化的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52038007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com