I am currently working on a small and easy Rest API using the Playframework 2.4 with Scala. I did define a simple case class and this gets transformed into Json rather easy. Now I would like to have the object (and if the result is an list, each entry in this list) named.
Is this possible in an easy manner? I just found this, but it does not really solve my issue.
case class Employee(name: String, address: String, dob: Date, joiningDate: Date, designation: String)
// Generates Writes and Reads for Feed and User thanks to Json Macros
implicit val employeeReads = Json.reads[Employee]
implicit val employeeWrites = Json.writes[Employee]
So, right now I do get
{
"name": "a name",
"address": "an address",
...
}
But I would like to see something like:
"employee": {
"name": "a name",
"address": "an address",
...
}
For a list of objects the same rule should apply:
"employees": [
"employee": {
"name": "a name",
"address": "an address",
...
},
...
]
This possible using the given Writes Macros? I am slightly lost right now ;-(