Workaround to https://issues.scala-lang.org/browse/SI-7046 If compiler fails to detect subclasses automatically, user can specify it manually using this annotation
Subclass annotated with this annotation will be selected if none of classes match provided type.
On case classes with single field it forces serializer to write this field directly to JSON, omitting object wrapper.
On case classes with single field it forces serializer to write this field directly to JSON, omitting object wrapper. On sealed classes/traits it forces serializer to omit type tags.
Specifies a key to use in case classes instead of field name
Specifies a key to use in case classes instead of field name
case class A(@key("field") a: String) implicit val aFormat = Json.generate[A] Json.toJson(A("123")).toString == "{\"field\":\"123\"}"
JSON key
Without @plainOption annotation Option fields are treated just like they are supposed to be - an optional fields that can be either present in object or not.
Without @plainOption annotation Option fields are treated just like they are supposed to be - an
optional fields that can be either present in object or not. Using this annotation you can switch
to a fallback behavior - serialize Options either as []
or [value]
Json
macros will refuse to generate formatter for types with this annotations, with only exception:
if you explicitly ask it to do so, e.g.:
Json
macros will refuse to generate formatter for types with this annotations, with only exception:
if you explicitly ask it to do so, e.g.:
@requireImplicit case class Something(field1: String, ...) implicit val somethingFormat = Json.generate[Something] // works
It is useful to make sure that recursive generation will not go too deep and will use existing implicits.
By default serializer omits fields that are equal to their default values.
By default serializer omits fields that are equal to their default values. Using this annotation you can ask it to emit them.
This annotation can be applied either to whole class or per field.
Workaround to https://issues.scala-lang.org/browse/SI-7046 If compiler fails to detect subclasses automatically, user can specify it manually using this annotation
Class