Fork me on GitHub
#reitit
<
2022-02-10
>
DenisMc10:02:56

Hi, I have a ring/reitit application. My json key values in my REST spec use snake case (underscores between lower case words), while in my handler I use kebab case for keywords (as per the clojure idiom). I’m struggling to figure out what coercion middleware I should use to coerce my requests and responses so that the keywords are updated dynamically on the way in and the way out to resolve this mismatch. Any tips on what I should do? Thanks in advance.

DenisMc13:02:51

Ok, I’ve resolved this now -

(m/create
  (-> m/default-options
      (assoc-in
        [:formats "application/json" :encoder-opts]
        {:encode-key-fn csk/->snake_case_string
         :bigdecimals true})
      (assoc-in
        [:formats "application/json" :decoder-opts]
        {:decode-key-fn csk/->kebab-case-keyword
         :bigdecimals true})
      ))
does the trick.