Formats for copying one play.api.libs.json.JsObject field to another field name during read.
Similar to TypedFormats but flattens definition
into the main body:
Formats for case class
s constructed with Json.format
can fail with an exception if the
constructor checks a condition with require.
Formats for case class
s constructed with Json.format
can fail with an exception if the
constructor checks a condition with require. These formats catch the exception and return
the appropriate JsError.
Formats a subclass of a variable-schema superclass.
Formats a subclass of a variable-schema superclass.
Variable-schema objects must have a type name (string) and a definition (JSON). The schema of the definition is specified based on the type name. These formats read the type name and then appropriately handle the JSON definition.
For example, the type names for a user id object may be "guest" and "registered" and the corresponding definitions may include a random string for the guest and an integer id for the registered user.
sealed trait UserId case class GuestUserId(id: String) object GuestUserId { implicit val format: OFormat[GuestUserId] = TypedFormats.typedDefinitionFormat("guest", Json.format[GuestUserId]) } case class RegisteredUserId(id: Int) object RegisteredUserId { implicit val format: OFormat[RegisteredUserId] = TypedFormats.typedDefinitionFormat("registered", Json.format[RegisteredUserId]) }
The JSON object looks like:
{ "typeName": "<some name>", "definition": <some JSON> }
See OrFormats for defining UserId
's OFormat in this example.
Similar to TypedFormats but flattens
definition
into the main body: