tototoshi / play-json-naming   1.5.0

GitHub

Custom naming convention for play-json to map snake_case json to camelCase case classes

Scala versions: 2.13 2.12

play-json-naming

Scala CI

Custom naming convention for play-json to map snake_case json to camelCase case classes.

Releases

For Play 2.6 or later, I recommend to use play.api.libs.json.JsonNaming

play-json-naming version play-json version
1.5.0 2.9.x
1.4.0 2.8.x
1.3.2 2.7.x
1.2.0 2.6.x
1.1.0 2.5.x
1.0.0 2.4.x
0.2.0 2.3.x

Setup

libraryDependencies += "com.github.tototoshi" %% "play-json-naming" % "1.5.0"

Usage

import com.github.tototoshi.play.json.JsonNaming

case class Name(firstName: String, lastName: String)
case class User(id: Int, nameData: Name)

implicit val nameFormat = JsonNaming.snakecase(Json.format[Name])
implicit val userFormat = JsonNaming.snakecase(Json.format[User])

val jsonString = """{"id":1,"name_data":{"first_name":"Toshiyuki","last_name":"Takahashi"}}"""

Json.parse(jsonString).validate[User]
Json.toJson(User(1, Name("Toshiyuki", "Takahashi")))