Extending clojure.contrib.json.write/print-json

18 views
Skip to first unread message

Josip Gracin

unread,
May 12, 2009, 9:26:19 AM5/12/09
to clo...@googlegroups.com
Hi!

I'm querying a DB and getting java.sql.Timestamp in results, among
other things. When I use print-json on this, timestamps are
serialized as #<Timestamp "13:23...">.

Stuart, any chance you could make the dispatch function for
clojure.contrib.json.write/print-json more open for extensions?
Unless I'm missing something, changing ":else :default" to ":else
(class x)" in the print-json dispatch fn definition would enable
adding serialization for custom objects.

(defmulti
print-json (fn [x]
(cond (nil? x) nil
(map? x) :object
(coll? x) :array
(keyword? x) :keyword
:else :default)))

--
mr.sc. Josip Gracin, dipl.ing.
direktor razvoja
Inge-mark d.o.o., Zavrtnica 17, Zagreb
tel: +38516658139, +385919009420

Tom Faulhaber

unread,
May 13, 2009, 5:11:51 PM5/13/09
to Clojure
Josip,

You might want to look at Dan Larkin's clojure-json library at
http://github.com/danlarkin/clojure-json which supports extensions via
dispatch as you suggest.

Tom

Stuart Sierra

unread,
May 13, 2009, 7:57:47 PM5/13/09
to Clojure
Hi Josip,
The latest version of c.c.json dispatches on the "type" function,
which in turn uses "class." It should be pretty easily extendible.
-Stuart Sierra

Josip Gracin

unread,
May 14, 2009, 4:46:49 AM5/14/09
to clo...@googlegroups.com
On Thu, May 14, 2009 at 1:57 AM, Stuart Sierra
<the.stua...@gmail.com> wrote:
> The latest version of c.c.json dispatches on the "type" function,
> which in turn uses "class."  It should be pretty easily extendible.

Thanks!

Reply all
Reply to author
Forward
0 new messages