edn serialization

This commit is contained in:
Jeremy Penner 2013-05-08 20:35:22 -04:00
parent 4d5e8c2c43
commit c60013f21f

21
src/hottub/serialize.clj Normal file
View file

@ -0,0 +1,21 @@
(ns hottub.serialize
(:require [clojure.edn :as edn]))
(defmethod print-dup clojure.lang.PersistentQueue [o w]
(.append w "#hottub/queue ")
(print-dup (into [] o) w))
(defn deserialize-queue [l]
(into clojure.lang.PersistentQueue/EMPTY l))
(defn write
([o] (with-open [w (java.io.StringWriter.)]
(write o w)
(.toString w)))
([o w] (print-dup o w)))
(defmulti read class)
(defmethod read String [s] (read (java.io.StringReader. s)))
(defmethod read java.io.Reader [r]
(with-open [pbr (java.io.PushbackReader. r)]
(edn/read {:readers {'hottub/queue deserialize-queue}} pbr)))