Clojure's transit不支持开箱即用的Joda时间格式。如何为org.joda.time.DateTime
添加写支持?
答案 0 :(得分:8)
添加此功能:
(def joda-time-writer
(transit/write-handler
(constantly "m")
#(-> % coerce/to-date .getTime)
#(-> % coerce/to-date .getTime .toString)))
并像这样使用它:
(transit/writer out :json
{:handlers {org.joda.time.DateTime joda-time-writer}})
答案 1 :(得分:0)
要使用ring-middleware-format工作,请使用David J发布的joda-time-writer
函数执行此操作。
(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}})))