org.coursera.common

jsonformat

package jsonformat

Visibility
  1. Public
  2. All

Value Members

  1. object CopyingFormats

    Formats for copying one play.api.libs.json.JsObject field to another field name during read.

  2. object FlatTypedFormats

    Similar to TypedFormats but flattens definition into the main body:

    Similar to TypedFormats but flattens definition into the main body:

    {
      "typeName": "<some name>",
      "definitionField1": &lt;a field from the definition object&gt;,
      "definitionField2": &lt;another field from the definition object&gt;
    }
  3. object JsonFormats

  4. object OrFormats

  5. object RequiringFormats

    Formats for case classs constructed with Json.format can fail with an exception if the constructor checks a condition with require.

    Formats for case classs 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.

  6. object TypedFormats

    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": &lt;some JSON&gt;
    }

    See OrFormats for defining UserId's OFormat in this example.

Ungrouped