I am trying to find help for applying JsonFormat extended for DefaultJsonProtocol to a class containing a sequence of objects.
So for classes:
class Person(val name: String, [......], val adresses: Seq[Adress])
class Adress(val streetname: String, val plz: BigDecimal, val city: String)
Now I would like to apply my JsonFormat:
object PersonJsonProtocol extends DefaultJsonProtocol {
implicit object PersonJsonFormat extends RootJsonFormat[Person] {
def write(pers: Person) = JsObject(
"name" -> JsString(pers.name),
[......],
"adresses" -> JsArray(pers.adresses)
)
def read(value: JsValue) = {...}
}
But actually I'm not sure how to do this. I looked at the spray documentation and json, google, stackoverflow and Co. I am completely new to Scala / Spray and maybe I just don’t understand the point. So maybe someone here is so kind as to help me. Without an address sequence, I will work.
With JsArray, as shown in the example, I get a type mismatch. It scans the list [JsValue], but also converts it to a list of inconsistencies.
AdressJsonProtocol :
"" → AdressJsonFormat.write(pers.adresses), ...