我有一个案例课:
case class OpcTagPlaybook(name: String, tags: Seq[OpcTagAtTime], looped: Boolean, enabled: Option[String])
带有一个可选的启用字段,它将包含一个日期。 Spray Json描述了编码/解码:
implicit val opcTagPlaybookFormat = jsonFormat4(OpcTagPlaybook)
还有akka http中的路线:
post {
entity(as[OpcTagPlaybook]) { playbook =>
val playbookCreated: Future[_] =
(opcTagPlaybookActor ? UpsertPlaybook(playbook))
onSuccess(playbookCreated) { _ =>
log.info("Created playbook [{}]", playbook.name)
complete((StatusCodes.Created, "ok"))
}
}
})
由于某些原因,没有createdAt字段的发布失败:
发布:
{"name": "test1",
"tags":[{"offset": 100, "tag": "hello", "value": "yo"}],
"looped": true
}
失败:
The request content was malformed:
Object is missing required member 'enabled'
如果我发布的帖子给了我另一个错误:
{"name": "test1",
"tags":[{"offset": 100, "tag": "hello", "value": "yo"}],
"looped": true,
"enabled": "2018-08-08"
}
给予
The request content was malformed:
spray.json.JsString cannot be cast to scala.Option
我假设这是akka http之间的相互作用,所以我将更加手动地处理输入,但是我只是想了解我在这里做错了什么。