ninny-json

JSON typeclasses that know the difference between null and absent fields

View the Project on GitHub nrktkt/ninny-json

Automatic derivation for ToJson and FromJson

Rather than implementing ToJson and FromJson by hand, you can generate them automatically using

Full-auto derivation for ToJson and FromJson

If you like you can even skip the declaration by mixing in AutoToJson or AutoFromJson, or importing nrktkt.ninny.Auto._.

Modifying field names with annotations

You can change the name of a field being read to/from JSON using the @JsonName annotation.

Using default values for optional fields

If your case class has optional parameters then you can use their default values when a field is absent by importing the feature flag FromJsonAuto.useDefaults in the scope of the derivation for your FromJson.

Handling null references

We don’t usually expect to have null references in Scala. So the default behavior is for null references to be passed to ToJson instances where they could be handled for a specific type.
However if you need to handle null references generally we have NullPointerBehavior.
By providing an instance of NullPointerBehavior in the scope of your ToJson derivation you can control if null references are passed to ToJson instances or if a value is provided instead. NullPointerBehavior.Ignore and IgnorePointerBehavior.WriteNull are provided the typical uses cases.