Package

play.api

json

Permalink

package json

Visibility
  1. Public
  2. All

Type Members

  1. trait ContextualJson extends AbstractContext with Annotations with ReadsMacro with WritesMacro

    Permalink

    The library considers context-aware JSON processing.

    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 = ""
    }

Value Members

  1. object ContextlessProtocolMacro

    Permalink
  2. object ProtocolMacro

    Permalink
  3. package context

    Permalink
  4. package macros

    Permalink

  5. object protocol

    Permalink

    Marks a case class to be part of json protocol.

    Marks a case class to be part of json protocol. The annotation ensures proper creation of context-aware Reads and Writes for the class. The processor adds markup Protocol trait to the class and creates reads and writes implicit within the class companion providing implicit converters into JSON.

    This class can be extended to make it local within different namespace. For example, suggested use is:

    package foo
    
    case class Context()
    
    object Protocol extends ContextualJson with JsonContext {
      override type Context = foo.Context
      class protocol extends play.api.json.protocol
    }

    And then the use is

    import foo.Protocol._
    
    @protocol case class Foo()

    However, this class can be also used directly.

Ungrouped