Reputation: 896
I've the following model:
case class Person(name: String, age: Int, job: Option[String])
object PersonJsonFormats {
implicit val personFormat = Json.format[Person]
}
Converting a Person
object into Json (e.g. with Json.toJson(person)
) produces the following Json object.
{
"name": "John",
"age": 10,
"job": "gardener"
}
What should I change in order to produce an object like the following instead?
[
{
"name": "name",
"value" : "John"
},
{
"name": "age",
"value": 10
},
{
"name": "job",
"value": "gardener"
}
]
I know I could write custom Reads
and Writes
but I want to write something I can apply to every case class
Upvotes: 1
Views: 78
Reputation: 3699
If you don't want to write custom Reads and Writes and want something that you can apply to every case class
, you probably should use macros to to this.
That's how the original automatic implicit converters are build.
Places to look:
Upvotes: 2