File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66 (java.util Date Map List Set SimpleTimeZone UUID)
77 (java.sql Timestamp)
88 (java.text SimpleDateFormat)
9+ (java.time Instant)
910 (clojure.lang IPersistentCollection Keyword Symbol)))
1011
1112(definline write-start-object [^JsonGenerator jg wholeness]
127128 (g/i? Timestamp obj) (let [sdf (doto (SimpleDateFormat. date-format)
128129 (.setTimeZone (SimpleTimeZone. 0 " UTC" )))]
129130 (g/write-string ^JsonGenerator jg (.format sdf obj)))
131+ (g/i? Instant obj) (let [sdf (doto (SimpleDateFormat. date-format)
132+ (.setTimeZone (SimpleTimeZone. 0 " UTC" )))
133+ d (Date/from obj)]
134+ (g/write-string ^JsonGenerator jg (.format sdf d)))
130135 :else (g/fail obj jg ex))))
Original file line number Diff line number Diff line change 211211 (is (= {" foo" " 1970-01-01-0004" }
212212 (json/decode (json/encode {:foo (Instant/ofEpochSecond (long 0 ))}
213213 {:date-format " yyyy-MM-dd-uuuu" })))
214- " use [[java.text.SimpleDateFormat]] format rules" ))
214+ " use [[java.text.SimpleDateFormat]] format rules" )
215+
216+ (is (= {" foo" " 1970-01-01T00:00:00Z" }
217+ (json/decode
218+ (str (json/with-writer [(StringWriter. ) nil ]
219+ (json/write {:foo (Instant/ofEpochSecond (long 0 ))}))))))
220+
221+ (is (= {" foo" " 1970-01-01" }
222+ (json/decode
223+ (str
224+ (json/with-writer [(StringWriter. ) {:date-format " yyyy-MM-dd" }]
225+ (json/write {:foo (Instant/ofEpochSecond (long 0 ))})))))
226+ " write with given date format" ))
215227
216228(deftest test-uuid
217229 (let [id (UUID/randomUUID )
You can’t perform that action at this time.
0 commit comments