googleapis / googleapis/google-cloud-java

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

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

描述

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

贡献指南

打开贡献指南

调研方向

首先阅读 CustomClassMapper.java,尤其是 stack trace 中显示的 BeanMapper 反序列化路径。确定 mapper 配置如何支持 Kotlin 对没有无参构造函数的 data class 所采用的序列化和反序列化语义。完成的标准是 Firestore mapper 无需无参构造函数即可反序列化所描述的 MyEntity 形状。

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

评估

技术栈
java, kotlin
领域
databases
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
30/100

把新 issue 发到你的邮箱

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