OWrites

play.api.libs.json.OWrites
See theOWrites companion trait

Attributes

Companion
trait
Graph
Supertypes
trait PathWrites
class Object
trait Matchable
class Any
Self type
OWrites.type

Members list

Value members

Concrete methods

def apply[A](f: A => JsObject): OWrites[A]

Returns an instance which uses f as OWrites.writes function.

Returns an instance which uses f as OWrites.writes function.

Attributes

def of[A](implicit w: OWrites[A]): OWrites[A]
def pure[A](fixed: => A)(implicit wrs: OWrites[A]): OWrites[JsValue]
def transform[A](w: OWrites[A])(f: (A, JsObject) => JsObject): OWrites[A]

Transforms the resulting JsObject using the given function, which is also applied with the initial input.

Transforms the resulting JsObject using the given function, which is also applied with the initial input.

Value parameters

f

the transformer function

w

the initial writer

Attributes

def tuple2[A : Writes, B : Writes](name1: String, name2: String): OWrites[(A, B)]

Writes a tuple of two values to a JSON object, with custom field names.

Writes a tuple of two values to a JSON object, with custom field names.

Type parameters

A

the type of the first value

B

the type of the second value

val tuple2Writes: OWrites[(String, Int)] =
 OWrites.tuple2[String, Int]("name", "age")
tuple2Writes.writes("Bob" -> 30) // {"name":"Bob","age":30}

Value parameters

name1

the name of the first field

name2

the name of the second field

Attributes

def tuple3[A : Writes, B : Writes, C : Writes](name1: String, name2: String, name3: String): OWrites[(A, B, C)]

Writes a tuple of three values to a JSON object, with custom field names.

Writes a tuple of three values to a JSON object, with custom field names.

Type parameters

A

the type of the first value

B

the type of the second value

C

the type of the third value

val tuple3Writes: OWrites[(String, Int, Boolean)] =
 OWrites.tuple3[String, Int, Boolean]("name", "age", "isStudent")
tuple3Writes.writes(("Bob", 30, false))
// {"name":"Bob","age":30,"isStudent":false}

Value parameters

name1

the name of the first field

name2

the name of the second field

name3

the name of the third field

Attributes

def tuple4[A : Writes, B : Writes, C : Writes, D : Writes](name1: String, name2: String, name3: String, name4: String): OWrites[(A, B, C, D)]

Writes a tuple of four values to a JSON object, with custom field names.

Writes a tuple of four values to a JSON object, with custom field names.

Type parameters

A

the type of the first value

B

the type of the second value

C

the type of the third value

D

the type of the fourth value

val tuple4Writes: OWrites[(String, Int, Boolean, Double)] =
 OWrites.tuple4[String, Int, Boolean, Double]("name", "age", "isStudent", "score")
tuple4Writes.writes(("Bob", 30, false, 91.2))
// {"name":"Bob","age":30,"isStudent":false,"score":91.2}

Value parameters

name1

the name of the first field

name2

the name of the second field

name3

the name of the third field

name4

the name of the fourth field

Attributes

Inherited methods

def at[A](path: JsPath)(implicit wrs: Writes[A]): OWrites[A]

Attributes

Inherited from:
PathWrites
def jsPick(path: JsPath): Writes[JsValue]

Attributes

Inherited from:
PathWrites

Attributes

Inherited from:
PathWrites

Attributes

Inherited from:
PathWrites
def list[A](implicit writes: Writes[A]): Writes[List[A]]

Attributes

Inherited from:
ConstraintWrites
def map[A](implicit writes: Writes[A]): OWrites[Map[String, A]]

Attributes

Inherited from:
ConstraintWrites
def nullable[A](path: JsPath)(implicit wrs: Writes[A]): OWrites[Option[A]]

writes a optional field in given JsPath : if None, doesn't write field at all. Please note we do not write "null" but simply omit the field when None If you want to write a "null", use ConstraintWrites.optionWithNull[A]

writes a optional field in given JsPath : if None, doesn't write field at all. Please note we do not write "null" but simply omit the field when None If you want to write a "null", use ConstraintWrites.optionWithNull[A]

Attributes

Inherited from:
PathWrites
def of[A](implicit w: Writes[A]): Writes[A]

Attributes

Inherited from:
ConstraintWrites
def optionWithNull[A](implicit wa: Writes[A]): Writes[Option[A]]

Pure Option Writer[T] which writes "null" when None which is different from JsPath.writeNullable which omits the field when None

Pure Option Writer[T] which writes "null" when None which is different from JsPath.writeNullable which omits the field when None

Attributes

Inherited from:
ConstraintWrites
def pruned[A]: Writes[A]

Attributes

Inherited from:
ConstraintWrites
def pure[A](fixed: => A)(implicit wrs: Writes[A]): Writes[JsValue]

Attributes

Inherited from:
ConstraintWrites
def pure[A](path: JsPath, fixed: => A)(implicit wrs: Writes[A]): OWrites[JsValue]

Attributes

Inherited from:
PathWrites
def seq[A](implicit writes: Writes[A]): Writes[Seq[A]]

Attributes

Inherited from:
ConstraintWrites
def set[A](implicit writes: Writes[A]): Writes[Set[A]]

Attributes

Inherited from:
ConstraintWrites

Deprecated and Inherited methods

def pruned[A](implicit w: Writes[A]): Writes[A]

Attributes

Deprecated
true
Inherited from:
ConstraintWrites

Implicits

Implicits

implicit val contravariantfunctorOWrites: ContravariantFunctor[OWrites]
implicit val functionalCanBuildOWrites: FunctionalCanBuild[OWrites]