score:4

Accepted answer

the json macro inception is not a good choice here, because this case is too complex. it only supports classic case, you cannot map values for exemple.

in this situation, you need a specific formater

import play.api.libs.json._
import play.api.libs.functional.syntax._
import anorm._

implicit val playerformat = (
    (__ \ "id").formatnullable[long] and
    (__ \ "name").formatnullable[string] and
    (__ \ "group" \ "id").format[long]
)((id, name, group) => player(id.map(id(_)).getorelse(notassigned), name, group), 
  (p: player) => (p.playerid.tooption, p.name, p.groupid))

it's a little bit complex, as your requirements are ;)


Related Query

More Query from same tag