This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-06-05
Channels
- # aleph (4)
- # announcements (2)
- # aws (37)
- # babashka (20)
- # beginners (105)
- # calva (30)
- # cider (6)
- # clerk (8)
- # cljs-dev (2)
- # clojars (8)
- # clojure (18)
- # clojure-brasil (1)
- # clojure-europe (25)
- # clojure-nl (1)
- # clojure-norway (21)
- # clojure-sweden (7)
- # clojure-uk (5)
- # clr (2)
- # cursive (37)
- # datalevin (2)
- # emacs (6)
- # events (2)
- # graalvm (35)
- # graphql (1)
- # hyperfiddle (3)
- # lsp (4)
- # malli (1)
- # off-topic (7)
- # pedestal (7)
- # practicalli (8)
- # reitit (5)
- # releases (4)
- # remote-jobs (1)
- # shadow-cljs (15)
- # xtdb (19)
hey y'all, is there an example out there of using reitit.ring.middleware.muuntaja
and configuring it to encode joda time objects? here's how the router is getting constructed:
(defn router
[routes]
(reitit-ring/router
routes
{:data {:coercion reitit.coercion.malli/coercion
:muuntaja muuntaja/instance
:middleware [;; swagger & openapi
swagger/swagger-feature
openapi/openapi-feature
;; query-params & form-params
reitit-parameters/parameters-middleware
;; content-negotiation
reitit-muuntaja/format-negotiate-middleware
;; encoding response body
reitit-muuntaja/format-response-middleware
;; decoding request body
reitit-muuntaja/format-request-middleware
;; coercing response bodys
reitit-ring-coercion/coerce-response-middleware
;; coercing request parameters
reitit-ring-coercion/coerce-request-middleware
;; multipart
multipart/multipart-middleware]}}))
I’m doing something sort of along those lines. I have my own namespace where I create a muuntaja instance that incorporates custom read-/write-handlers, not for joda time objects but for tick instant
’s. (And I can’t remember for sure but there might be joda time objects underneath there somewhere).
thank you! I think I figured it out. Here's what I have:
;; in :require
(:import
(com.fasterxml.jackson.datatype.joda JodaModule)
(org.joda.time LocalDate))
(def jsonista-mapper
"Handle joda->json encoding"
(jsonista/object-mapper
{:modules [(JodaModule.)]}))
(def muuntaja-instance
(muuntaja/create
(assoc-in muuntaja/default-options
[:formats "application/json" :encoder-opts :modules]
[(JodaModule.)])))
(defn router
[routes]
(reitit-ring/router
routes
{:data {:coercion reitit.coercion.malli/coercion
:muuntaja muuntaja-instance
:middleware [ ;; swagger & openapi
swagger/swagger-feature
openapi/openapi-feature
;; query-params & form-params
reitit-parameters/parameters-middleware
;; content-negotiation
reitit-muuntaja/format-negotiate-middleware
;; encoding response body
reitit-muuntaja/format-response-middleware
;; decoding request body
reitit-muuntaja/format-request-middleware
;; coercing response bodys
reitit-ring-coercion/coerce-response-middleware
;; coercing request parameters
reitit-ring-coercion/coerce-request-middleware
;; multipart
multipart/multipart-middleware]}}))
That looks good. I think there is also a single format-middleware
that bundles together all three.
oh cool