避免使用 Circe json 序列化器序列化为 null

Paw*_*elN 3 json scala circe

如何避免使用 Circe json 序列化器将 None 序列化为 null?我无法强制该库跳过“无”的序列化字段。有可能实现吗?

Paw*_*elN 5

我找到了解决方案。我们可以通过我们的配置提供实例 Printer 的隐式变量。 https://github.com/circe/circe/blob/master/modules/core/shared/src/main/scala/io/circe/Printer.scala 我们可以将 dropNullKeys 设置为 null,一切都会像魅力一样工作。