xuwei-k / play-json-extra   0.9.0

MIT License Website GitHub

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

Scala versions: 2.13 2.12
Scala.js versions: 1.x

play-json-extra

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.8

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

for scala-js

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