Search code examples
jsonscalashapelessspray-json

JsValue serialization fail


In my app I'm using https://github.com/fommil/spray-json-shapeless library for serializaion, but I have problem with this class:

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

implicit val JobResultFormat: RootJsonFormat[JobResult] = {
  import shapeless._
  cachedImplicit
}

Without result field of type JsValue everything works fine but with it i have following exception:

[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]

Any advices how to handle it.


Solution

  • I solved my problem by changing result to JsObject and cleaning project before rebuild.

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