Custom Transit writer for Joda time in Clojure

Clojure transit does not support the Joda time format out of the box. How to add record support for org.joda.time.DateTime ?

+6
source share
2 answers

Add this function:

 (def joda-time-writer (transit/write-handler (constantly "m") #(-> % coerce/to-date .getTime) #(-> % coerce/to-date .getTime .toString))) 

And use it as follows:

 (transit/writer out :json {:handlers {org.joda.time.DateTime joda-time-writer}}) 
+7
source

To get this to work with the ring intermediate format, do this using the joda-time-writer function sent by David J.

 (defn wrap-format [handler] (let [transit-opts {:handlers {org.joda.time.DateTime joda-time-writer}}] (wrap-restful-format handler {:response-options {:transit-json transit-opts :transit-messagepack transit-opts}}))) 
0
source

Source: https://habr.com/ru/post/974565/


All Articles