My JSON result have the naming convention like:
"account_id"
"location_type"
But my case classes have:
case class Employee(accountId: Int, locationType: String)
Is there a way to override the case classes property when JSON is being parsed?
Automapping: https://www.playframework.com/documentation/2.5.x/ScalaJsonAutomated
答案 0 :(得分:2)
There are two things you can do here:
Rename fields in your case class:
case class Employee(account_id: Int, location_type: String)
Write your custom Format
:
import play.api.libs.functional.syntax._
import play.api.libs.json._
implicit val employeeFormat: Format[Employee] = (
(__ \ "account_id").format[Int] and
(__ \ "location_type").format[String]
)(Employee.apply, unlift(Employee.unapply))