googleapis / googleapis/google-cloud-java

[java-firestore] Feature Request: Support configuration of mapper to allow use of Kotlin serialization/deserialization semantics

Aperta
#13,137 1 commento 6 reazioni 0 assegnatari Vedi su GitHub
api: firestore type: feature request
Lingua principale
Java
Stelle
2.1k
Fork
1.2k
Merge medio
1g 23h
PR unite (30g)
154

Descrizione

**Is your feature request related to a problem? Please describe.**

Currently the implementation mostly follows "Java" way of serialization. Kotlin allows to be more precise, consider following snippet:

```kotlin
data class MyEntity(
val name: String
)
```

When using Jackson's object mapper with KotlinModule:

```kotlin
val objectMapper = ObjectMapper()
.registerModule(KotlinModule())
```

We are able to (de)serialize such entities even though they don't have any default constructor.

Unfortunately Firestore's object mapper doesn't use Jackson and the Kotlin's advantages cannot be used. When using a data class without default constructor, it leads to:

```
Could not deserialize object. Class MyEntity does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped
at com.google.cloud.firestore.CustomClassMapper.deserializeError(CustomClassMapper.java:614) ~[google-cloud-firestore-2.1.0.jar:2.1.0]
at com.google.cloud.firestore.CustomClassMapper.access$200(CustomClassMapper.java:53) ~[google-cloud-firestore-2.1.0.jar:2.1.0]
at com.google.cloud.firestore.CustomClassMapper$BeanMapper.deserialize(CustomClassMapper.java:800) ~[google-cloud-firestore-2.1.0.jar:2.1.0]
at com.google.cloud.firestore.CustomClassMapper$BeanMapper.deserialize(CustomClassMapper.java:792) ~[google-cloud-firestore-2.1.0.jar:2.1.0]
at com.google.cloud.firestore.CustomClassMapper.convertBean(CustomClassMapper.java:593) ~[google-cloud-firestore-2.1.0.jar:2.1.0]
```

**Describe the solution you'd like**
Profit from the Kotlin's features and allow for a no argument constructor.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.