0

I have case class

 case class CreateOffer(playerId: Option[PlayerId], modifier: Double, expiry: DateTime, start: DateTime, notification: String)

When I try in test to Post this in spray

val req = Post("/create", createOffer) ~>
      addHeader("token", playerToken) ~>
      handleExceptions(exceptionHandler)(router.route) ~>
      check {
       //
      }

I have exception

spray.json.DeserializationException: Object is missing required member 'modifier'

to marshaling I use

jsonFormat5(CreateOffer.apply)

In previous tests I don't have this issue, but after refactoring it appeared

route look that

              path("create") {
                post {
                  traceName("create") {
                    handleWith { createOffer: CreateOffer =>
                      Future[CreateOffer] {
                        controller.createOffer(createOffer)
                      }
                    }
                  }
                }
              }

****************UPDATE****************

Finally I can debug my test in IntelliJ and I found that problem probably is in ProductFormats.scala (spray.json). First parameter is Option and reading work ok, but second is normal value and I have problem:

protected def fromField[T](value: JsValue, fieldName: String)
                                     (implicit reader: JsonReader[T]) = value match {
    case x: JsObject if
      (reader.isInstanceOf[OptionFormat[_]] &  //I think that in this line is problem 
        !x.fields.contains(fieldName)) =>
      None.asInstanceOf[T]
    case x: JsObject =>
      try reader.read(x.fields(fieldName))
      catch {
        case e: NoSuchElementException =>
          deserializationError("Object is missing required member '" + fieldName + "'", e, fieldName :: Nil)
        case DeserializationException(msg, cause, fieldNames) =>
          deserializationError(msg, cause, fieldName :: fieldNames)
      }
    case _ => deserializationError("Object expected in field '" + fieldName + "'", fieldNames = fieldName :: Nil)
  }

0 Answers0