I pass record instances using transit+json format to api POST handler. It works fine when used with :body. But when :body-params is used: record instances are unexpectedly turned into plain maps.
I tracked it to compojure.api.coercion/coerce-request! which calls walk/keywordize-keys which in turn recursively turns record instances into maps (which is a questionable behaviour on its own: https://clojure.atlassian.net/browse/CLJ-2505).
It's told to keywordize for :body-params in meta.clj.
Library Version(s)
2.0.0-alpha29
Problem
I pass record instances using
transit+json
format toapi
POST handler. It works fine when used with:body
. But when:body-params
is used: record instances are unexpectedly turned into plain maps.Test code:
Cause
I tracked it to
compojure.api.coercion/coerce-request!
which callswalk/keywordize-keys
which in turn recursively turns record instances into maps (which is a questionable behaviour on its own: https://clojure.atlassian.net/browse/CLJ-2505).It's told to keywordize for
:body-params
in meta.clj.This issue looks very similar to this PR about disabling keywordizing in
:body
: https://github.com/metosin/compojure-api/pull/265. We discussed it on Slack back in 2017.Workaround
I had to patch
walk/postwalk
so that it doesn't touch instances of my protocol (usingclj-fakes
):