cats
typeclass instances for the play-json
library.
You'll need to add JCenter to your resolvers. In your build.sbt
:
resolvers += Resolver.jcenterRepo
libraryDependencies += "com.iravid" %% "play-json-cats" % 0.2
play-json-cats
is currently published only for Scala 2.11. Once play-json
supports Scala 2.12, this package will be updated.
import com.iravid.playjsoncats.implicits._
import play.api.libs.json._
case class Person(name: String, i: Int)
val rn: Reads[String] = Reads(j => (j \ "name").validate[String])
val ri: Reads[Int] = Reads(j => (j \ "i").validate[Int])
val rp: Reads[Person] = (rn |@| rp).map(Person)
val res: JsResult[Person] = rp.reads(Json.parse("""
{ "name": "iravid", "i": 42 }
"""))
cats
typeclass instances for the play-json
library.