Home

Awesome

play-products Maven Central

A convenient syntactic sugar to combine monoidal structures (e.g. Reads, OWrites, OFormat), powered by shapeless.

Consider the following definition:

case class User(name: String, age: Int)

With play-products you can define a JSON codec for it as follows:

import julienrf.products.syntax._
import play.api.libs.json.{__, Reads}

val userReads: OFormat[User] =
 (
   (__ \ "name").format[String] :*:
   (__ \ "age").format[Int]
 ).as[User]

Instead of the current syntax supported out of the box by Play:

import play.api.libs.functional.syntax._
import play.api.libs.json.{__, Reads}

val userReads: OFormat[User] =
 (
   (__ \ "name").format[String] ~
   (__ \ "age").format[Int]
 )(User.apply _, unlift(User.unapply _))

Features

License

This content is released under the MIT License.