1
我想解組json字符串。但最終會出現錯誤。無法正確理解錯誤。解組json在spray-json中
下面是代碼:
import akka.actor.ActorSystem
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.stream.ActorMaterializer
import spray.json._
import scala.concurrent.Future
import org.json4s.{Serialization, jackson}
object Test extends App{
val json = """{
| "entries": [
| {
| ".tag": "folder",
| "name": "Camera Uploads",
| "path_lower": "/camera uploads",
| "path_display": "/Camera Uploads",
| "id": "id:up-mXElWkuAAAAAAAAAHsw"
| },
| {
| ".tag": "file",
| "name": "roboQuestions.mov",
| "path_lower": "/roboquestions.mov",
| "path_display": "/roboQuestions.mov",
| "id": "id:up-mXElWkuAAAAAAAAAUUg",
| "client_modified": "2016-08-23T16:24:53Z",
| "server_modified": "2016-08-23T18:13:34Z",
| "rev": "1a9d06ecb0f6",
| "size": 110339964
| }
| ],
| "cursor": "AAFA2NDm5UrAaaG6s2gwGbyh1Fq5Na6EE-UMpccSv2PrvAmfh-54645-6f4S2cYmnj0G0r1aMMy0KlP9VWllp3oWIaYtAKDQfj3zSCiWo_lB98MnRlEKDA0sRexYsTI68dlaDM_Yimiy",
| "has_more": false
|}""".stripMargin.parseJson
implicit val system = ActorSystem()
implicit val materializer = ActorMaterializer()
implicit val jacksonSerialization: Serialization = jackson.Serialization
import concurrent.ExecutionContext.Implicits.global
final case class BoxFolder(id:String, `.tag`:Option[String], name:Option[String], path_lower:Option[String], path_display:Option[String], client_modified:Option[String], server_modified:Option[String], rev:Option[String], size:Option[Long])
object BoxFolder extends DefaultJsonProtocol with SprayJsonSupport
{
implicit val folderFormat = jsonFormat9(BoxFolder.apply)
}
final case class BoxList(entries:List[BoxFolder], cursor:String, has_more:Boolean)
object BoxList extends DefaultJsonProtocol with SprayJsonSupport
{
implicit val folderFormat = jsonFormat3(BoxList)
}
val resFuture:Future[BoxList] = Unmarshal(json).to[BoxList]
resFuture.map(println)
system.terminate()
}
錯誤:
Error:(279, 53) could not find implicit value for parameter um: akka.http.scaladsl.unmarshalling.Unmarshaller[spray.json.JsValue,Test.BoxList]
val resFuture:Future[BoxList] = Unmarshal(json).to[BoxList]
Error:(279, 53) not enough arguments for method to: (implicit um: akka.http.scaladsl.unmarshalling.Unmarshaller[spray.json.JsValue,Test.BoxList], implicit ec: scala.concurrent.ExecutionContext, implicit mat: akka.stream.Materializer)scala.concurrent.Future[Test.BoxList].
Unspecified value parameters um, ec, mat.
val resFuture:Future[BoxList] = Unmarshal(json).to[BoxList]