Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Transit writer for Joda time in Clojure

Clojure's transit does not support the Joda time format out of the box. How can I add write support for org.joda.time.DateTime?

like image 399
David J. Avatar asked Aug 29 '14 19:08

David J.


1 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 like this:

(transit/writer out :json
                    {:handlers {org.joda.time.DateTime joda-time-writer}})
like image 85
David J. Avatar answered Sep 28 '22 02:09

David J.