I have a case class which has three parameters, and renders as:
{
"name": "foo",
"items": [
"bar"
],
}
For this I have a jsonFormatter in my own JsonProtocol class.
Although how could I render the JSON as:
[
{
"name": "foo",
"items": [
"bar"
]
}
]
...?
The way I was approaching it was to create the JSON object using:
List(TheCaseClass(name, items)).toJson.asJsObject
...and having a formatter such as:
implicit val formatter = jsonFormat1(List[TheCaseClass])
...although then I'm getting an error that my JsonProtocol class couldn't be initialized.
The only other way I can think of doing it is to have something like a 'TheCaseClassItems' class which could be a collection of the 'TheCaseClass' objects and using a formatter such as:
implicit def theCaseClassItems Items[T :JsonFormat] = jsonFormat1(TheCaseClassItems.apply[T])
...although this would yield the JSON:
{
"items": [
{
"name": "foo",
"items": [
"bar"
]
}
]
}
...which isn't what I'm after. Could you advise the best approach? Thanks!