无法使用喷雾将其反序列化。我无法理解为什么defaultJson协议不起作用。请注意我是scala和spray的新手。
case class Job(param1:Boolean,param2:String,joblist:List[JobList])
case class
JobList(param3:String,param4:Option[Seq[Map[String,String]]],....,param10)
implicit object transformJson extends JsonFormat[Job]{
override def read(json: JsValue): Job = json match {
case JsObject(fields) =>
Job(fields("param1").convertTo[Boolean],
fields("param2").convertTo[String],
fields("jobslist").convertTo[List[JobList]]
)
case _ => deserializationError("Not a Record")
}
override def write(obj: Job): JsValue = ???
}
错误:(55,39)找不到JsonReader或JsonFormat类型 布尔 Job(fields(“param1”)。convertTo [Boolean],错误:(55,39)没有足够的参数用于方法convertTo :(隐式证据$ 1: spray.json.JsonReader [布尔])布尔值。未指定的值参数 证据$ 1 作业(字段( “参数1”)。的ConvertTo [布尔]
我先尝试过这个
object transformJson extends DefaultJsonProtocol{
implicit val job=jsonFormat3(Job)
implicit val joblist=jsonFormat7(JobList)
}
错误:(53,39)无法找到证据参数的隐含值 类型TransformJson.JF [Array [joblist]] 隐式val jobformat = jsonFormat3(作业)错误:(53,39)方法jsonFormat3的参数不够:
答案 0 :(得分:0)
当然我没有告诉如何处理JobList
case class Job(param1:Boolean,param2:String,joblist:List[JobList])
case class JobList(param3:String,param4:Option[Seq[Map[String,String]]],....,param10)
object TransformJobList extends DefaultJsonProtocol {
implicit val joblist= jsonFormat7(JobList)
implicit object transformJson extends JsonFormat[Job]{
override def read(json: JsValue): Job = json match {
case JsObject(fields) =>
Job(fields("param1").convertTo[Boolean],
fields("param2").convertTo[String],
fields("jobslist").convertTo[List[JobList]]
)
case _ => deserializationError("Not a Record")
}
override def write(obj: Job): JsValue = ???
}
}