You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
caseclassFoo(
name : Option[String] =Noneage : 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
The text was updated successfully, but these errors were encountered:
Have you tried if @transient from the com.github.polokhotnyuk.jsoniter_scala.macros package (or from the scala package with CodecMakerConfig.withScalaTransientSupport(true) argument for the make call) placed at the field definition works for your case?
Please check both approaches shown in these tests.
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:
and I have this JSON:
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
The text was updated successfully, but these errors were encountered: