cheshire
cheshire copied to clipboard
Date's don't default to ISO formatting when in the key position
generate-string formats dates as strings. But it does that differently when the same date is in the key versus value position:
(require 'cheshire.core)
(import 'java.util.Date)
(def now (Date.))
(cheshire.core/generate-string {now now})
=> "{\"Thu Apr 17 15:39:35 PDT 2014\":\"2014-04-17T22:39:35Z\"}"
This is surprising.
My guess is that keys are simply coerced to strings.
This is because keys are assumed to be either "stringy", or as keywords. So the key Date
is just having .toString
called on it.
See: https://github.com/dakrone/cheshire/blob/master/src/cheshire/generate.clj#L67-L69