jsoniter-scala icon indicating copy to clipboard operation
jsoniter-scala copied to clipboard

totally Skip Serialization of optional class field.

Open samuelorji opened this issue 1 year ago • 1 comments

Hi,

Is there a way to completely skip the serialization of an optional class field with a default value ?

As an example,

say I have a class Foo:


case class Foo(
         name : Option[String] = None
         age : Int
   )

and I have this JSON:

 {
     "name" : "Jack",
      "age" : 23
 }
 

Is there a way I can make the JsonCodecMaker skip the serialization of the "name" field in the json and by default just use the default value supplied in the case class. I tried using this config, but it doesn't work as expected because according to the doc, it will skip serialization if the field is the same as the default value, whereas I'm looking for an option where it completely skips the serialization of the field irrespective of the json value

samuelorji avatar Oct 08 '24 16:10 samuelorji