yada icon indicating copy to clipboard operation
yada copied to clipboard

Date coercion of json body in :post method does not work

Open stijnopheide opened this issue 9 years ago • 0 comments

Minimal example to reproduce:

(def json-server
  (yada/listener ["/" (yada/resource {:methods {:post {:consumes   ["application/json"]
                                                       :produces   ["application/json"]
                                                       :parameters {:body {:date schema.core/Inst}}
                                                       :response   (fn [ctx]
                                                                     (-> ctx :parameters :body))}}})]
                 {:port 3333}))

Request:

curl 'http://localhost:3333/' -H 'Content-Type: application/json' -H 'Accept: application/json' --data-binary '{"date":"2016-08-21T20:52:50.250Z"}'

Expected result:

{"date":"2016-08-21T20:52:50.250Z"}

Actual result:

{
  "status": 400,
  "message": "Bad Request",
  "id": "8f13b08b-60df-4698-8cd2-b703212c63df",
  "error": {
    "error": "clojure.lang.ExceptionInfo: Malformed body {:status 400, :error {:date (not (instance? java.util.Date a-java.lang.String))}}",
    "data": "{:status 400, :error {:date (not (instance? java.util.Date a-java.lang.String))}}"
  }
}

stijnopheide avatar Oct 10 '16 14:10 stijnopheide