How to remove null values in list of objects using Circe

Jan*_*art 3 scala circe

I'm trying to encode a list of objects using Circe, something that looks similar to:

val test = Seq(MyObject("hello", None, 1, 2, None)

I'm trying to parse this using Circe:

test.asJson

But this creates the JSON object:

[
  {
    name: "hello",
    someVal: null,
    someNum: 1,
    anotherNum: 2,
    anotherVal: null
  }
]
Run Code Online (Sandbox Code Playgroud)

I've tried running asJson with .dropNullValues, but that doesn't seem to access the null values inside of the object. Is there a way to drop the null values inside of the objects?

I'm expecting something more like this:

[
  {
    name: "hello",
    someNum: 1,
    anotherNum: 2
  }
]
Run Code Online (Sandbox Code Playgroud)

che*_*hry 8

尝试 test.asJson.deepDropNullValues