JsValue 序列化失败



在我的应用程序中,我正在使用 https://github.com/fommil/spray-json-shapeless 库进行序列化,但是我对这个类有问题:

case class FooResult(var id: Option[String], jobId: String, completedAt: DateTime, result: JsValue) extends JobResult
implicit val JobResultFormat: RootJsonFormat[JobResult] = {
  import shapeless._
  cachedImplicit
}

如果没有 JsValue 类型的结果字段,一切正常,但有了它,我有以下例外:

[error] /home/mgosk/projects/spark-service/spark-rest-api/src/main/scala/com/xxx/http/services/SparkService.scala:134: ambiguous implicit values:
[error]  both object JsValueFormat in trait AdditionalFormats of type com.xxx.spark.json.ServiceJsonProtocol.JsValueFormat.type
[error]  and method familyFormat in trait LowPriorityFamilyFormats of type [T, Repr](implicit gen: shapeless.LabelledGeneric.Aux[T,Repr], implicit sg: shapeless.Cached[shapeless.Strict[com.xxx.spark.json.ServiceJsonProtocol.WrappedRootJsonFormat[T,Repr]]], implicit tpe: shapeless.Typeable[T])spray.json.RootJsonFormat[T]
[error]  match expected type spray.json.JsonFormat[spray.json.JsValue]

任何建议如何处理它。

我在重建之前通过将结果更改为JsObject和清洁项目来解决我的问题。

case class FooResult(var id: Option[String], jobId: String, completedAt: DateTime, result: JsObject) extends JobResult

最新更新