googleapis / googleapis/google-cloud-java

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

Abierto
#13,140 3 comentarios 1 reacción 0 asignados Ver en GitHub
api: firestore type: question
Lenguaje dominante
Java
Estrellas
2.1k
Forks
1.2k
Merge medio
1 d 23 h
PR fusionados (30 d)
154

Descripción

#### 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.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.