我在实例化 Firestore 客户端时收到此警告。
fs = FirestoreClient.getFirestore();
警告附带解决方案,通过以下方式实例化客户端:
FirestoreOptions options =
FirestoreOptions.newBuilder().setTimestampsInSnapshotsEnabled(true).build();
Firestore firestore = options.getService();
建议,在正确实例化默认 Firebase 应用程序后,我从 options.getService() 中获得空引用
这种情况仅发生在 Firebase admin sdk java 版本中。它隐藏了 NodeJs 版本的警告。
根据java版本的文档,我不需要新的构建器,至少我可以找到它。
当前包版本(来自 gradle 构建文件):
compile 'com.google.firebase:firebase-admin:6.7.0'
更新:
我现在注意到 createTime 属性返回的是时间戳而不是日期,因此看起来无论客户端的初始化方式如何,行为都已经发生了变化。
最佳答案
对于 Admin SDK,您应该通过 FirebaseOptions
来探索该选项。
FirebaseOptions options =
FirebaseOptions.builder()
.setCredentials(credentials)
.setFirestoreOptions(FirestoreOptions.newBuilder()
.setTimestampsInSnapshotsEnabled(true)
.build())
.build();
FirebaseApp.initializeApp(options);
Firestore db = FirestoreClient.getFirestore();
关于firebase - 警告 : The behavior for java. 存储在 Firestore 中的 util.Date 对象将会更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54323809/