Encodes a tagged type by adding an extra field to the base A JSON representation.
Encodes a tagged type by adding an extra field to the base A JSON representation.
For instance, consider the following type definition:
sealed trait Foo case class Bar(s: String, i: Int) extends Foo case object Baz extends Foo
And also:
implicit val fooOWrites: OWrites[Foo] = derived.flat.owrites((__ \ "type").write)
The JSON representation of Bar("quux", 42) is then the following JSON object:
{
"type": "Bar",
"s": "quux",
"i": 42
}A way to encode the type tag as a JSON object (whose fields will be merged with the base JSON representation)
Encodes a tagged type by creating a JSON object wrapping the actual A JSON representation.
Encodes a tagged type by creating a JSON object wrapping the actual A JSON representation. This wrapper
is an object with just one field whose name is the type tag.
For instance, consider the following type definition:
sealed trait Foo case class Bar(s: String, i: Int) extends Foo case object Baz extends Foo
The JSON representation of Bar("quux", 42) is the following JSON object:
{
"Bar": {
"s": "quux",
"i": 42
}
}