This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-12
Channels
- # bangalore-clj (4)
- # beginners (77)
- # boot (71)
- # cider (10)
- # clara (1)
- # cljs-dev (52)
- # cljsjs (28)
- # cljsrn (1)
- # clojure (390)
- # clojure-dev (5)
- # clojure-india (1)
- # clojure-italy (5)
- # clojure-nl (24)
- # clojure-poland (4)
- # clojure-russia (123)
- # clojure-spec (71)
- # clojure-taiwan (2)
- # clojure-uk (8)
- # clojurescript (236)
- # core-matrix (6)
- # cursive (19)
- # datomic (16)
- # defnpodcast (2)
- # editors (1)
- # emacs (36)
- # garden (2)
- # hoplon (5)
- # jobs (1)
- # jobs-discuss (10)
- # juxt (47)
- # luminus (4)
- # lumo (6)
- # off-topic (207)
- # om (1)
- # onyx (20)
- # pedestal (40)
- # perun (2)
- # re-frame (8)
- # reagent (48)
- # ring (2)
- # ring-swagger (2)
- # specter (13)
- # unrepl (89)
- # vim (6)
@juliobarros it looks like you'd have to specify custom transit encoder/decoder in the options: https://github.com/metosin/muuntaja#default-options something like
(defn joda-time-writer [t]
...)
then in the options:
...
:encoder [(partial formats/make-transit-encoder
:json
{:handlers {org.joda.time.DateTime joda-time-writer})]
...
so here's a full working version for the encoder:
(ns ...
(:require
...
[cognitect.transit :as transit]
[clj-time.coerce :as coerce]
[muuntaja.core :as m]
[muuntaja.format.transit :as formats]))
(def joda-time-writer
(transit/write-handler
(constantly "m")
#(some-> % coerce/to-date .getTime)
#(some-> % coerce/to-date .getTime .toString)))
(defn wrap-formats [handler]
(let [wrapped (wrap-params
(wrap-format
handler
(update
m/default-options
:formats
merge
{"application/transit+json"
{:decoder [(partial formats/make-transit-decoder :json)]
:encoder [#(formats/make-transit-encoder
:json
(merge
%
{:handlers {org.joda.time.DateTime joda-time-writer}}))]}})))]
(fn [request]
;; disable wrap-formats for websockets
;; since they're not compatible with this middleware
((if (:websocket? request) handler wrapped) request))))
I added an example in luminus docs https://github.com/luminus-framework/luminus/blob/master/resources/md/responses.md#adding-custom-encoders-with-muuntaja