I am have this json object
val jsonObject = """
{
"name" : "camara",
"project" : {
"key" : "DOC",
"name" : "Dockerfiles"
},
"cloneUrl" : "https://server/scm/doc/camara.git",
"links" : {
"clone" : [ {
"href" : "https://server/scm/doc/camara.git",
"name" : "http"
}, {
"href" : "ssh://git@server:7999/doc/camara.git",
"name" : "ssh"
} ],
"self" : [ {
"href" : "url1"
},
{
"href" : "url2"
} ]
}
}
"""
And with this case class and Reader:
case class Project(name: String, project: String, projectUrl: List[String])
implicit val projectReader: Reads[Project] = (
(JsPath \ "name").read[String] and
(JsPath \ "project" \ "name").read[String] and
(JsPath \ "links" \ "self" \\ "href").read[List[String]])(Project.apply _)
I try to parse to this model:
Json.parse(jsonObject).validate[Project] match {
case value: JsSuccess[Project] =>
println(" >> " + value.get)
case error: JsError =>
println(error)
}
The I get this error
JsError(List((/links/self//href,List(ValidationError(error.path.result.multiple,WrappedArray())))))
I have no idea how to extract those hrefs from the self array into the Project class to look like this:
Project(camara,Dockerfiles,List(url1, url2))
I have looked everywhere, on the internet for a simple example that would help me on the right track, but I haven't managed to find anything that helps.
How can I solve this issue without changing my Project class's structure ?