This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-10
Channels
- # announcements (6)
- # architecture (2)
- # babashka (30)
- # beginners (90)
- # calva (21)
- # cider (22)
- # clj-kondo (27)
- # cljs-dev (7)
- # clojure (132)
- # clojure-europe (51)
- # clojure-nl (12)
- # clojure-norway (3)
- # clojure-spec (3)
- # clojure-uk (5)
- # clojurescript (69)
- # cloverage (9)
- # conjure (5)
- # core-async (54)
- # cursive (14)
- # datomic (34)
- # emacs (7)
- # fulcro (10)
- # graalvm (40)
- # graalvm-mobile (2)
- # gratitude (2)
- # improve-getting-started (1)
- # introduce-yourself (1)
- # jobs-discuss (61)
- # leiningen (5)
- # malli (6)
- # off-topic (59)
- # pathom (11)
- # polylith (38)
- # reagent (3)
- # reitit (3)
- # rewrite-clj (3)
- # shadow-cljs (53)
- # tools-build (35)
- # transit (8)
- # vim (62)
- # web-security (26)
- # xtdb (4)
This might actually apply to reitit more generally https://clojurians.slack.com/archives/CLDK6MFMK/p1644471747071999
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.
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.