For now it is impossible to convenietly generate encoder that does not produce null values at the output.
Scenario:
@JsonCodec case class Params(p1: String, p2: Option[Int])
def process(a: Json): Unit = ???
val params = Params("abc", None)
process(json"""{"requestId": 123, "params": $params}""")
And I want the a not to contain null values.
I know I can:
preprocess a in the process() method - apply dropNullValues, use customized printer, etc
postprocess json where I use interpolation
customize codec by .mapJson(.dropNullValues)
First and second one seems like wrong place to solve this issue - its like workaround for misbehaving codec.
Third option requires lots of bolierplate code: Switching from annotation to manual derivation (creation of companion objects, etc), and then mapping derived encoder output.
I believe most correct solution would be to add io.circe.generic.extras.Configuration.dropNullValues. Then one could use it with derived codecs as well as with @ConfiguredJsonCodec.
For now it is impossible to convenietly generate encoder that does not produce null values at the output.
Scenario:
And I want the a not to contain null values. I know I can:
a
in theprocess()
method - applydropNullValues
, use customized printer, etc.mapJson(.dropNullValues)
First and second one seems like wrong place to solve this issue - its like workaround for misbehaving codec.
Third option requires lots of bolierplate code: Switching from annotation to manual derivation (creation of companion objects, etc), and then mapping derived encoder output.
I believe most correct solution would be to add
io.circe.generic.extras.Configuration.dropNullValues
. Then one could use it with derived codecs as well as with@ConfiguredJsonCodec
.