I have the following case class rows which i want to further filter and represent them as a json
case class Row(id: UUID, ownerId: UUID, typeId: UUID, name: String, value: String)
json format I want to represent in
{
"owner": "ownerId",
"configurations": {
"typeId1": {
"name1": "value1",
"name2": "value2"
},
"typeId2": {
"name3": "value3",
"name4": "value4"
}
}
}
Now I'm converting this into the following result type
case class Data(owner: String, configurations: Map[String, Map[String, String]])
I'm doing the above using the following function
def convert(rows: Seq[Row]): Data =
Data(owner = <SomedatabaseCall to populate this>,
configurations = rows.groupMapReduce(_.typeId/*Actually need to populate this with a database call as well*/)(r => Map(r.name -> r.value))(_ ++ _))
I have three questions here :
How can you marshall the Map object of Map of Maps using spray-json, I'm not able to clear that out?
Now if we see the
typeIdis actually a UUID and I need to make another database call to find thetypeName, what the best way to populate this and make the custom json object I want to create ?I can't use the
groupMapReducemethod since we use 2.12 version of scala and I can't upgrade for other reasons. Any alternative to group by thetypeName
My suggestions:
circeinstead of spray-json. It has auto derivation feature that helps to you go fast without any custom/manual encoder decoder ex: