避免使用Circe json序列化器序列化为null [英] Avoid serialize to null using Circe json serializer

查看:143
本文介绍了避免使用Circe json序列化器序列化为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to avoid serializing None to null using Circe json serializer? I am not able to force this library to skip serializing fields which are None. Is it possible to achieve?

推荐答案

我找到了解决方案.我们可以通过我们的配置提供实例打印机的隐式变量. https: //github.com/circe/circe/blob/master/modules/core/shared/src/main/scala/io/circe/Printer.scala 我们可以将dropNullKeys设置为null,一切都可以正常运行.

I found the solution. We can provide implicit variable of instance Printer with our configuration. https://github.com/circe/circe/blob/master/modules/core/shared/src/main/scala/io/circe/Printer.scala We can set dropNullKeys to null and everything is working like a charm.

这篇关于避免使用Circe json序列化器序列化为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆