googleapis / googleapis/google-cloud-java
[java-firestore] Inconsistent behaviour between Java SDK and other SDKs when saving/reading properties that start with "is"
- Vorherrschende Sprache
- Java
- Sterne
- 2.1k
- Forks
- 1.2k
- Ø Merge
- 1 T. 23 Std.
- Gemergte PRs (30 T.)
- 154
Beschreibung
#### 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.
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.