I have a Play-scala v2.3 application. Looking from this guide about Json Combinators, I'm trying to do this:
object Application extends Controller {
case class Foo(id: String, docs: List[Map[String, _]])
implicit val fooReads = (
(JsPath \ "id").read[String] and
(JsPath \ "docs").read[List[Map[String, _]]]
)(Foo.apply _)
...
}
But then I got compile error:
No Json deserializer found for type List[Map[String, _]]. Try to implement an implicit Reads or Format for this type.
(JsPath \ "docs").read[List[Map[String, _]]]
^
This is the example json that need to be read:
{
"id": "001",
"docs": [
{
"name": "Billy",
"level": 2,
"marked": false
},
{
"name": "Fred",
"level": 5,
"marked": true
}
]
}
I also have tried this:
case class Foo(id: String, docs: Map[String, _])
implicit val fooReads = (
(JsPath \ "id").read[String] and
(JsPath \ "docs").read[Map[String, _]]
)(Foo.apply _)
Same error too.
It seems Play's JSON combinator doesn't work for Map type. Anyone know how to solve this?
Maptype, but notMap[String, _]. The_is untyped, so it won't know what to do with it. Why are you trying to useMap[String, _]in the first place?Json Macros are known to accept Option/Seq/List/Set & Map[String, _], could it be a hint that it should work (at past?). The reason to use Map because I have a service method that acceptList[Map[String, _]]parameter, although I can use a list of case class for the docs, but then I have to convert it to List[Map[String, _]].Map[String, _], butMap[String, Int],Map[String, String], etc.. for types that make sense.Reads/Writesfor it. If they don't have a uniform type, then what do they have? It's still possible to make it work in some way, just not with the macro.