googleapis / googleapis/google-cloud-java

[java-firestore] Inconsistent behaviour between Java SDK and other SDKs when saving/reading properties that start with "is"

未关闭
#13,140 3 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
api: firestore type: question
主要语言
Java
星标
2.1k
派生
1.2k
平均合并
1 天 23 小时
30 天内合并 PR
157

描述

#### Environment details

1. OS type and version: MacOS 10.15.5
2. Java version: 8
3. firestore version(s): 6.12.2

#### Problem

Hi, I'm seeing inconsistent behaviour when saving and reading from Firestore using the Java SDK (using Kotlin).
I'm saving a document that looks like this:

```kotlin
data class Whatever(
val result: Result? = null
)

data class Result(
val isSuccess: Boolean = false
)
```

When I save this to Firestore like this:

```kotlin
val whatever = Whatever(result = Result(isSuccess = true))

collection.document(docId).set(whatever).get()
```

then the `isSuccess` property is saved as a `success` field in Firestore (I verified this by checking the field on the Firebase Console).

However, when I want to read this same document from Firestore like this:

```
collection.document(docId).get().get().toObject(Whatever::class.java)
then the isSuccess property is not populated with true and the default false is returned.
```

then the `isSuccess` property is not populated with `true` and the default `false` is returned.

#### Steps to reproduce

1. Create a document from the JS SDK using an object with a property that starts with is (e.g., `{ "isSuccess": true }`).

2. Read the document from the Java SDK and convert it to an object using the `toObject()` method.

When I try to read the object on step 2 the app fails to convert the document to a Java object because the JS SDK saved the name of the field as `isSuccess` and there is no way for the Java SDK to convert that apparently. I tried naming the property in the Kotlin class both `isSuccess` and `success` and they both failed to get the proper value from the underlying document field.

These are the results I get when I print the document field vs the Kotlin object:

```
// Printing the document
{isSuccess=true}

// Printing the Kotlin class
TestClass(success=null)
TestClass(isSuccess=null)
```

#### Other details

This was first reported here: https://github.com/firebase/firebase-admin-java/issues/472 and I moved it to this repository as indicated by someone in the Google team.

贡献指南

打开贡献指南

调研方向

Reproduce the issue with the shown Kotlin data classes and a Firestore document, then compare the stored field name with the result of Java SDK `toObject()`. Trace how `isSuccess` and `success` are handled during serialization and deserialization. Done means Java SDK reads documents written by both the Java and JS SDKs with the boolean value preserved.

由索引模型根据 Issue 内容生成。

评估

技术栈
firebase, java, kotlin
领域
databases
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。