Skip to content

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

License

Notifications You must be signed in to change notification settings

tototoshi/play-json-naming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages