xuwei-k / play-json-extra

playframework2 json extra module. provide convenience functions for define Format, Reads, Writes

Website GitHub

play-json-extra

Build Status Scala.js scaladoc

motivation and example

I think following way is so verbose.

import play.api.libs.json._
import play.api.libs.functional.syntax._

final case class User(id: Long, name: String)

object User {
  implicit val format: OFormat[User] = (
    (__ \ "id").format[Long] and // I want to omit `Long` and `String`
    (__ \ "name").format[String]
  )(apply _, Function.unlift(unapply))
}

Play provides Json macros. Yes it is useful, but I want to specify Json keys explicitly sometime like argonaut casecodecN

import play.api.libs.json._
import play.jsonext._

final case class User(id: Long, name: String)

object User {
  implicit val format: OFormat[User] =
    CaseClassFormats(apply _, unapply _)("id", "name")
}

latest stable version for play-json 2.7

libraryDependencies += "com.github.xuwei-k" %% "play-json-extra" % "0.6.1"

for scala-js

libraryDependencies += "com.github.xuwei-k" %%% "play-json-extra" % "0.6.1"

snapshot version for play-json 2.7

resolvers += Opts.resolver.sonatypeSnapshots

libraryDependencies += "com.github.xuwei-k" %% "play-json-extra" % "0.6.2-SNAPSHOT"

for scala-js

resolvers += Opts.resolver.sonatypeSnapshots

libraryDependencies += "com.github.xuwei-k" %%% "play-json-extra" % "0.6.2-SNAPSHOT"

old version