Json spray implicit UUID conversion

I have a user model

case class User(name: String, email: String, password: Option[String] = None, key: Option[UUID] = None)

With marshaler spray

object UserJsonSupport extends DefaultJsonProtocol with SprayJsonSupport {
  implicit val userFormat = jsonFormat4(User)
}

It worked until I reworked the key field from Option[String]to Option[UUID], and now I get two compilation errors:

Error:(8, 40) could not find implicit value for evidence parameter of type in.putfood.http.UserJsonSupport.JF[Option[java.util.UUID]]
  implicit val userFormat = jsonFormat4(User)
                                       ^
Error:(8, 40) not enough arguments for method jsonFormat4: (implicit evidence$16: in.putfood.http.UserJsonSupport.JF[String], implicit evidence$17: in.putfood.http.UserJsonSupport.JF[String], implicit evidence$18: in.putfood.http.UserJsonSupport.JF[Option[String]], implicit evidence$19: in.putfood.http.UserJsonSupport.JF[Option[java.util.UUID]], implicit evidence$20: ClassManifest[in.putfood.model.User])spray.json.RootJsonFormat[in.putfood.model.User].
Unspecified value parameters evidence$19, evidence$20.
  implicit val userFormat = jsonFormat4(User)
                                   ^

I realized that since this problem was resolved, it should work without the need to provide my own UUID non-serializer. Am I mistaken or is it completely different?

Is it possible that he does not like being inside Option?

+4
source share
1 answer

This was probably resolved, however, I came across the same issue recently (when using akka-http v10.0.0), and I was able to solve it by specifying the following

  implicit object UUIDFormat extends JsonFormat[UUID] {
    def write(uuid: UUID) = JsString(uuid.toString)
    def read(value: JsValue) = {
      value match {
        case JsString(uuid) => UUID.fromString(uuid)
        case _              => throw new DeserializationException("Expected hexadecimal UUID string")
      }
    }
  }

Fidesmo API.


Update:

, . < >

+2

All Articles