 
 (defmethod decode :default [message]
   (throw (RuntimeException. (str "Received unknown message encoding: " (get-encoding message)))))
-
-
-;; Fallback to Java serialization for undefined print-dup methods
-
-(defn serialize [object]
-  (with-open [baos (java.io.ByteArrayOutputStream.)
-              oos (java.io.ObjectOutputStream. baos)]
-    (.writeObject oos object)
-    (.toString baos "ISO-8859-1")))
-
-(defn deserialize [s]
-  (with-open [bais (java.io.ByteArrayInputStream. (.getBytes s "ISO-8859-1"))
-              ois (java.io.ObjectInputStream. bais)]
-    (.readObject ois)))
-
-(defmethod print-dup :default [o w]
-  (.println System/out (str "WARN: using Java serialization for " (.getName (class o))))
-  (.write w "#=(immutant.messaging.codecs/deserialize ")
-  (print-dup (serialize o) w)
-  (.write w ")"))


(defmethod decode :clojure [message]
  "Turn a string into a clojure data structure"
  (load-string (.getText message)))

(defmethod decode :json [message]
  "Turn a string into a json data structure"
  (json/read-json (.getText message)))

(defmethod decode :text [message]
  "Treats the message payload as a raw string. No decoding is done."

(defn ^{:private true} get-encoding [^javax.jms.Message msg]
  (keyword (.getStringProperty msg encoding-header-name)))

;; Encode

(defmulti encode (fn [_ _ {encoding :encoding}] (or encoding :clojure)))
