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")
}
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"