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