Trait

play.api.json

ContextualJson

Related Doc: package json

Permalink

trait ContextualJson extends AbstractContext with Annotations with ReadsMacro with WritesMacro

The library considers context-aware JSON processing. It means that for every data processing it accepts current execution context containing, e.g., user's identity, application state, user's privileges, etc. This enables us to use these contextual data within conditions and transformations to provide/read only data matching these conditions.

Instances of ContextualJson implements the protocol and provides Reads and Writes materializers, including context type and implicit conversions. Everywhere we want to use the protocol we have to import everything from our protocol instance.

Example

Define the context

case class MyContext( requestId: Long )

Define the protocol

// optionally @play.api.json.protocol.removeNulls
// optionally @play.api.json.protocol.strict
object Protocol extends ContextualJson {

  override type Context = MyContext

  // space for further configuration, helpers, writes, reads, etc.
}

And then we import it everywhere we use the protocol

import Protocol._

@protocol
case class Foo() {
   @when( _.identity.hasPrivilege( "ADMIN" ) )
   var restricted: String = ""
}
Linear Supertypes
WritesMacro, ReadsMacro, Annotations, AbstractContext, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ContextualJson
  2. WritesMacro
  3. ReadsMacro
  4. Annotations
  5. AbstractContext
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract type Context

    Permalink

    type of used context, e.g., MyContext.

    type of used context, e.g., MyContext.

    case class MyContext( identity: User )
    Definition Classes
    AbstractContext
  2. trait ContextualReads[T <: context.ReadsMacro.Protocol] extends (context.ReadsMacro.Context) ⇒ Reads[T]

    Permalink

    Context-aware Reads

    Context-aware Reads

    Definition Classes
    ReadsMacro
  3. trait ContextualWrites[T <: context.WritesMacro.Protocol, +Writes[_] <: Writes[_]] extends (context.WritesMacro.Context) ⇒ Writes[T]

    Permalink

    Context-aware Writes

    Context-aware Writes

    Definition Classes
    WritesMacro
  4. trait Protocol extends AnyRef

    Permalink

    markup trait marking classes for Reads/Writes materialization

    markup trait marking classes for Reads/Writes materialization

    Definition Classes
    AbstractContext
  5. class WriteTransformContext[T] extends AnyRef

    Permalink

    encapsulates a Context with the processed instance

    encapsulates a Context with the processed instance


    Note: There is Any because we are unable to parametrize WriteContext[ T ] and use it within @when[ T ]. Scala would require manual providing [ T ] also when we do not need it. The solution would be to generate the type via macros, but annotation macro cannot be used within traits and it cannot be pulled out because it uses path-dependent Context type. In consequence, this falls back to Any and getter model[ T ], because of lack of support in macros.

    Definition Classes
    AbstractContext
  6. case class WriteUpdateContext[+T] extends Product with Serializable

    Permalink
    Definition Classes
    AbstractContext
  7. case class WriteWhenContext extends Product with Serializable

    Permalink

    encapsulates a Context with the processed instance

    encapsulates a Context with the processed instance


    Note: There is Any because we are unable to parametrize WriteContext[ T ] and use it within @when[ T ]. Scala would require manual providing [ T ] also when we do not need it. The solution would be to generate the type via macros, but annotation macro cannot be used within traits and it cannot be pulled out because it uses path-dependent Context type. In consequence, this falls back to Any and getter model[ T ], because of lack of support in macros.

    Definition Classes
    AbstractContext

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. implicit val $protocol: ContextualJson.this.type

    Permalink
  4. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  5. object ContextualReads

    Permalink

    set of helper functions used within ContextualReads macro to simplify the implementation

    set of helper functions used within ContextualReads macro to simplify the implementation

    Definition Classes
    ReadsMacro
  6. object WriteTransformContext

    Permalink
    Definition Classes
    AbstractContext
  7. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  8. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. macro def contextlessReads[T <: Protocol]: Reads[T]

    Permalink
    Definition Classes
    ReadsMacro
  10. macro def contextlessWrites[T <: Protocol]: Writes[T]

    Permalink
    Definition Classes
    WritesMacro
  11. macro def contextualReads[T <: Protocol]: ContextualReads[T]

    Permalink

    macro materializer of context-aware Reads

    macro materializer of context-aware Reads

    Definition Classes
    ReadsMacro
  12. macro def contextualWrites[T <: Protocol]: ContextualWrites[T, Writes]

    Permalink

    macro materializer of context-aware Writes

    macro materializer of context-aware Writes

    Definition Classes
    WritesMacro
  13. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  14. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  15. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  16. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  17. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  18. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  19. object json

    Permalink
    Definition Classes
    Annotations
  20. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  21. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  22. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  23. implicit def reads[T <: Protocol](implicit context: Context, reads: ContextualReads[T]): Reads[T]

    Permalink

    resolver of context-aware reads into regular reads.

    resolver of context-aware reads into regular reads. Note: these resolved reads are valid only within given context!

    Definition Classes
    ReadsMacro
  24. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  25. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  26. implicit def unwrapWriteModelContext[T](context: WriteUpdateContext[T]): T

    Permalink
    Definition Classes
    AbstractContext
  27. implicit def unwrapWriteTransformContext[T](context: WriteTransformContext[T]): T

    Permalink
    Definition Classes
    AbstractContext
  28. implicit def unwrapWriteWhenContext(context: WriteWhenContext): Context

    Permalink

    implicit helper to unwrap write context into regular context

    implicit helper to unwrap write context into regular context

    Definition Classes
    AbstractContext
  29. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  30. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  32. implicit def writes[T <: Protocol, Writes[_] <: Writes[_]](implicit context: Context, writes: ContextualWrites[T, Writes]): Writes[T]

    Permalink

    resolver of context-aware writes into regular writes.

    resolver of context-aware writes into regular writes. Note: these resolved writes are valid only within given context!

    Definition Classes
    WritesMacro

Inherited from WritesMacro

Inherited from ReadsMacro

Inherited from Annotations

Inherited from AbstractContext

Inherited from AnyRef

Inherited from Any

Ungrouped