Custom naming convention for play-json to map snake_case json to camelCase case classes
Switch branches/tags
Clone or download
Latest commit ead4d92 Oct 31, 2017
Permalink
Failed to load latest commit information.
project Updated sbt version Jun 25, 2017
src Updated Play version to 2.6.0-M2 Mar 15, 2017
.gitignore init Jan 19, 2015
.travis.yml travis-ci Mar 15, 2017
LICENSE.txt Added LICENSE.txt Jan 19, 2015
README.md Update README.md Oct 31, 2017
build.sbt v1.2.0 Jun 25, 2017

README.md

play-json-naming

Build Status

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

Releases

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

play-json-naming version Play version
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.2.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")))