Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid serialize to null using Circe json serializer

Tags:

json

scala

circe

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?

like image 933
PawelN Avatar asked Apr 20 '26 13:04

PawelN


1 Answers

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.

like image 67
PawelN Avatar answered Apr 23 '26 08:04

PawelN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!