Permalink
Browse files

marshalling objects with play-json-naming 'snake_case'

  • Loading branch information...
1 parent 34133ee commit 4cffd64fa8ba3f99eba1309ebe6f09c3d6320131 @wlk committed Mar 25, 2016
Showing with 4 additions and 28 deletions.
  1. +3 −28 app/models/JsonMarshalling.scala
  2. +1 −0 build.sbt
@@ -1,5 +1,6 @@
package models
+import com.github.tototoshi.play.json.JsonNaming
import models.v1._
import play.api.libs.json._
@@ -27,33 +28,7 @@ trait JsonMarshalling {
implicit val deckFormat = Json.format[Deck]
- implicit val playerWrites = new Writes[Player] {
- def writes(p: Player) = Json.obj(
- "id" -> p.id,
- "name" -> p.name,
- "status" -> p.status,
- "version" -> p.version,
- "stack" -> p.stack,
- "bet" -> p.bet,
- "hole_cards" -> p.holeCards
- )
- }
+ implicit val playerWrites = JsonNaming.snakecase(Json.writes[Player])
- implicit val gameStateWrites = new Writes[GameState] {
- def writes(g: GameState) = Json.obj(
- "tournament_id" -> g.tournamentId,
- "game_id" -> g.gameId,
- "round" -> g.round,
- "bet_index" -> g.betIndex,
- "small_blind" -> g.smallBlind,
- "current_buy_in" -> g.currentBuyIn,
- "pot" -> g.pot,
- "minimum_raise" -> g.minimumRaise,
- "dealer" -> g.dealer,
- "orbits" -> g.orbits,
- "in_action" -> g.inAction,
- "players" -> g.players, //intellij complains here, but it's correct and project compiles OK
- "community_cards" -> g.communityCards
- )
- }
+ implicit val gameStateWrites = JsonNaming.snakecase(Json.writes[GameState])
}
View
@@ -15,6 +15,7 @@ libraryDependencies ++= Seq(
jdbc,
cache,
ws,
+ "com.github.tototoshi" %% "play-json-naming" % "1.1.0",
"org.scalatestplus.play" %% "scalatestplus-play" % "1.5.0-RC1" % Test
)

0 comments on commit 4cffd64

Please sign in to comment.