Packages

  • package root
    Definition Classes
    root
  • package play

    Play framework.

    Play framework.

    Play

    http://www.playframework.com

    Definition Classes
    root
  • package api

    Contains the public API for Scala developers.

    Contains the public API for Scala developers.

    Read configuration
    val poolSize = configuration.getInt("engine.pool.size")
    Use the logger
    Logger.info("Hello!")
    Define a Plugin
    class MyPlugin(app: Application) extends Plugin
    Create adhoc applications (for testing)
    val application = Application(new File("."), this.getClass.getClassloader, None, Play.Mode.DEV)
    Definition Classes
    play
  • package libs

    Contains various APIs that are useful while developing web applications.

    Contains various APIs that are useful while developing web applications.

    Definition Classes
    api
  • package json

    Json API

    Json API

    For example:

    import play.api.libs.json._
    import play.api.libs.functional.syntax._
    
    case class User(id: Long, name: String, friends: Seq[User] = Seq.empty)
    object User {
    
      // In this format, an undefined friends property is mapped to an empty list
      implicit val format: Format[User] = (
        (__ \ "id").format[Long] and
        (__ \ "name").format[String] and
        (__ \ "friends").lazyFormatNullable(implicitly[Format[Seq[User]]])
          .inmap[Seq[User]](_ getOrElse Seq.empty, Some(_))
      )(User.apply, unlift(User.unapply))
    }
    
    object MyController extends play.api.mvc.Controller {
       def displayUserAsJson(id: String) = Action {
          Ok(Json.toJson(User(id.toLong, "myName")))
       }
    
       def saveUser(jsonString: String)= Action {
         val user = Json.parse(jsonString).as[User]
         //myDataStore.save(user)
         Ok
       }
    }
    Definition Classes
    libs
  • object Json extends JsonFacade with JsMacros with JsValueMacros

    Helper functions to handle JsValues.

    Helper functions to handle JsValues.

    Definition Classes
    json
  • DefaultValues
  • JsValueWrapper
  • MacroOptions
  • WithOptions
c

play.api.libs.json.Json

WithOptions

final class WithOptions[Opts <: MacroOptions] extends JsonFacade with JsMacrosWithOptions[Opts]

JSON facade with some macro options.

Opts

the compile-time options

Source
Json.scala
Linear Supertypes
JsMacrosWithOptions[Opts], JsMacros, JsonFacade, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. WithOptions
  2. JsMacrosWithOptions
  3. JsMacros
  4. JsonFacade
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new WithOptions()
  2. new WithOptions(config: Aux[Opts])

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def arr(items: JsValueWrapper*): JsArray

    Returns a JsArray with given items.

    Returns a JsArray with given items.

    Definition Classes
    WithOptionsJsonFacade
    Annotations
    @inline()
  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def asciiStringify(json: JsValue): String

    Converts a JsValue to its string representation, escaping all non-ascii characters using \u005CuXXXX syntax.

    Converts a JsValue to its string representation, escaping all non-ascii characters using \u005CuXXXX syntax.

    This is particularly useful when the output JSON will be executed as javascript, since JSON is not a strict subset of javascript (see JSON: The JavaScript subset that isn't).

    import play.api.libs.json.{ Json, JsString }
    
    Json.asciiStringify(JsString("some\\u005Ctext\\u005C"))
    // => "some\\u005Ctext\\u005C"
    
    Json.stringify(JsString("some\\u005Ctext\\u005C"))
    // => "sometext"
    json

    the JsValue to convert A String with the json representation with all non-ascii characters escaped.

    Definition Classes
    WithOptionsJsonFacade
    Annotations
    @inline()
  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @HotSpotIntrinsicCandidate() @native()
  8. val config: Aux[Opts]
  9. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  10. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  11. macro def format[A]: OFormat[A]

    Creates a OFormat[T] by resolving, at compile-time, the case class fields or sealed family, and the required implicits.

    Creates a OFormat[T] by resolving, at compile-time, the case class fields or sealed family, and the required implicits.

    If any missing implicit is discovered, compiler will break with corresponding error.

    A

    the type for which the handler must be materialized

    import play.api.libs.functional.syntax._
    import play.api.libs.json.{ Json, JsonConfiguration, __ }
    
    case class User(userName: String, age: Int)
    
    val userFormat1 = Json.format[User]
    // macro-compiler replaces Json.format[User] by injecting into compile chain
    // the exact code you would write yourself. This is strictly equivalent to:
    val userFormat2 = (
       (__ \ implicitly[JsonConfiguration].naming("userName")).format[String] and
       (__ \ implicitly[JsonConfiguration].naming("age")).format[Int]
    )(User.apply, unlift(User.unapply))
    Definition Classes
    JsMacrosWithOptions → JsMacros
  12. def fromJson[T](json: JsValue)(implicit fjs: Reads[T]): JsResult[T]

    Converts a JsValue to a value of requested type T.

    Converts a JsValue to a value of requested type T.

    T

    The type of conversion result, only supported if a Reads implicit is available for.

    json

    the JsValue to convert

    Definition Classes
    WithOptionsJsonFacade
    Annotations
    @inline()
  13. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @HotSpotIntrinsicCandidate() @native()
  14. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @HotSpotIntrinsicCandidate() @native()
  15. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  16. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  17. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate() @native()
  18. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate() @native()
  19. def obj(fields: (String, JsValueWrapper)*): JsObject

    Returns a JsObject with given fields.

    Returns a JsObject with given fields.

    fields

    the object fields specified as pairs of name and value

    Definition Classes
    WithOptionsJsonFacade
    Annotations
    @inline()
  20. def parse(input: Array[Byte]): JsValue

    Parses some bytes representing a JSON input, and returns it as a JsValue.

    Parses some bytes representing a JSON input, and returns it as a JsValue.

    The character encoding used will be automatically detected as UTF-8, UTF-16 or UTF-32, as per the heuristics in RFC-4627.

    input

    the byte array to parse

    Definition Classes
    WithOptionsJsonFacade
    Annotations
    @inline()
  21. def parse(input: InputStream): JsValue

    Parses a stream representing a JSON input, and returns it as a JsValue.

    Parses a stream representing a JSON input, and returns it as a JsValue.

    input

    the InputStream to parse

    Definition Classes
    WithOptionsJsonFacade
    Annotations
    @inline()
  22. def parse(input: String): JsValue

    Parses a String representing a JSON input, and returns it as a JsValue.

    Parses a String representing a JSON input, and returns it as a JsValue.

    input

    the String to parse

    Definition Classes
    WithOptionsJsonFacade
    Annotations
    @inline()
  23. def prettyPrint(json: JsValue): String

    Converts a JsValue to its pretty string representation using default pretty printer (line feeds after each fields and 2-spaces indentation).

    Converts a JsValue to its pretty string representation using default pretty printer (line feeds after each fields and 2-spaces indentation).

    import play.api.libs.json.Json
    
    val res0 = Json.obj(
      "field1" -> Json.obj(
        "field11" -> "value11",
        "field12" -> Json.arr("alpha", 123L)
      )
    )
    // => {"field1":{"field11":"value11","field12":["alpha",123]}}
    
    Json.prettyPrint(res0)
    // =>
    // {
    //   "field1" : {
    //     "field11" : "value11",
    //     "field12" : [ "alpha", 123 ]
    //   }
    // }
    json

    the JsValue to convert A String with the json representation.

    Definition Classes
    WithOptionsJsonFacade
    Annotations
    @inline()
  24. macro def reads[A]: Reads[A]

    Creates a Reads[T] by resolving, at compile-time, the case class fields or sealed family, and the required implicits.

    Creates a Reads[T] by resolving, at compile-time, the case class fields or sealed family, and the required implicits.

    If any missing implicit is discovered, compiler will break with corresponding error.

    A

    the type for which the handler must be materialized

    import play.api.libs.json.{ Json, Reads }
    
    case class User(userName: String, age: Int)
    
    implicit val userReads: Reads[User] =
      Json.using[Json.MacroOptions with Json.DefaultValues].reads[User]
    Definition Classes
    JsMacrosWithOptions → JsMacros
  25. def stringify(json: JsValue): String

    Converts a JsValue to its string representation.

    Converts a JsValue to its string representation.

    import play.api.libs.json.Json
    
    val input = Json.obj(
      "field1" -> Json.obj(
        "field11" -> "value11",
        "field12" -> Json.arr("alpha", 123L)
      )
    )
    
    Json.stringify(input)
    // => {"field1":{"field11":"value11","field12":["alpha",123]}}
    json

    the JsValue to convert

    returns

    a String with the json representation

    Definition Classes
    WithOptionsJsonFacade
    Annotations
    @inline()
  26. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  27. def toBytes(json: JsValue): Array[Byte]

    Converts a JsValue to bytes (using UTF-8 encoding).

    Converts a JsValue to bytes (using UTF-8 encoding).

    json

    the JsValue to convert

    returns

    an Array[Byte] representing the UTF-8-encoded JSON

    Definition Classes
    WithOptionsJsonFacade
    Annotations
    @inline()
  28. def toJsObject[T](o: T)(implicit tjs: OWrites[T]): JsObject

    Converts any object writeable value to a JsObject.

    Converts any object writeable value to a JsObject.

    A value is writeable as an object, if a OWrites implicit is available for its type.

    T

    the type of the value to be written as JsObject

    o

    the value to convert as JSON object

    Definition Classes
    WithOptionsJsonFacade
    Annotations
    @inline()
  29. def toJson[T](o: T)(implicit tjs: Writes[T]): JsValue

    Converts any writeable value to a JsValue.

    Converts any writeable value to a JsValue.

    A value is writeable if a Writes implicit is available for its type.

    T

    the type of the value to be written as JSON

    o

    the value to convert as JSON

    Definition Classes
    WithOptionsJsonFacade
    Annotations
    @inline()
  30. def toString(): String
    Definition Classes
    AnyRef → Any
  31. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  32. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  33. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  34. macro def writes[A]: OWrites[A]

    Creates a OWrites[T] by resolving, at compile-time, the case class fields or sealed family, and the required implicits.

    Creates a OWrites[T] by resolving, at compile-time, the case class fields or sealed family, and the required implicits.

    If any missing implicit is discovered, compiler will break with corresponding error.

    A

    the type for which the handler must be materialized

    import play.api.libs.functional.syntax._
    import play.api.libs.json.{ Json, JsonConfiguration, __ }
    
    case class User(userName: String, age: Int)
    
    implicit val userWrites1 = Json.writes[User]
    // macro-compiler replaces Json.writes[User] by injecting into compile chain
    // the exact code you would write yourself. This is strictly equivalent to:
    implicit val userWrites2 = (
       (__ \ implicitly[JsonConfiguration].naming("userName")).write[String] and
       (__ \ implicitly[JsonConfiguration].naming("age")).write[Int]
    )(unlift(User.unapply))
    Definition Classes
    JsMacrosWithOptions → JsMacros

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

    (Since version 9)

Inherited from JsMacrosWithOptions[Opts]

Inherited from JsMacros

Inherited from JsonFacade

Inherited from AnyRef

Inherited from Any

Ungrouped