From 3af24f7343871bf0199a02bed31e6724533aaa99 Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Wed, 2 Nov 2011 13:49:38 -0700 Subject: [PATCH 1/2] Use cheshire instead of clojure.data.json. Should allow it to work with Clojure 1.3. --- project.clj | 6 +++--- src/com/mefesto/wabbitmq/content_type.clj | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/project.clj b/project.clj index 0bf89dc..7fe9902 100644 --- a/project.clj +++ b/project.clj @@ -3,7 +3,7 @@ :url "https://github.com/mefesto/wabbitmq" :license {:name "Eclipse Public License - v 1.0" :url "http://www.eclipse.org/legal/epl-v10.html"} - :dependencies [[org.clojure/clojure "1.2.0"] - [org.clojure/clojure-contrib "1.2.0"] + :dependencies [[org.clojure/clojure "1.2.1"] + [cheshire "2.0.2"] [com.rabbitmq/amqp-client "2.2.0"]] - :dev-dependencies [[swank-clojure "1.3.0-SNAPSHOT"]]) + :dev-dependencies [[swank-clojure "1.3.3"]]) diff --git a/src/com/mefesto/wabbitmq/content_type.clj b/src/com/mefesto/wabbitmq/content_type.clj index 71596fe..12627b3 100644 --- a/src/com/mefesto/wabbitmq/content_type.clj +++ b/src/com/mefesto/wabbitmq/content_type.clj @@ -1,5 +1,5 @@ (ns com.mefesto.wabbitmq.content-type - (:use [clojure.contrib.json :only (json-str read-json)])) + (:use [cheshire.core :only [generate-string parse-string]])) (defn- charset [type] (second (re-find #"charset=([^;]+)" type))) @@ -29,14 +29,14 @@ (defn application-json-encode [content-type data] (when data (if-let [charset (charset content-type)] - (-> (json-str data) (.getBytes charset)) - (-> (json-str data) (.getBytes))))) + (-> (generate-string data) (.getBytes charset)) + (-> (generate-string data) (.getBytes))))) (defn application-json-decode [content-type data] (when data (if-let [charset (charset content-type)] - (-> (String. data charset) (read-json)) - (-> (String. data) (read-json))))) + (-> (String. data charset) (parse-string)) + (-> (String. data) (parse-string))))) (def application-json [application-json? application-json-encode application-json-decode]) From c553b7bcdc6389ab74e7513f27b11f3426f0c486 Mon Sep 17 00:00:00 2001 From: mefesto Date: Tue, 8 Nov 2011 10:44:36 -0500 Subject: [PATCH 2/2] Updated calls to cheshire json to return maps with keywords as keys --- src/com/mefesto/wabbitmq/content_type.clj | 4 ++-- test/com/mefesto/wabbitmq/test_content_type.clj | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/com/mefesto/wabbitmq/content_type.clj b/src/com/mefesto/wabbitmq/content_type.clj index 12627b3..3a56754 100644 --- a/src/com/mefesto/wabbitmq/content_type.clj +++ b/src/com/mefesto/wabbitmq/content_type.clj @@ -35,8 +35,8 @@ (defn application-json-decode [content-type data] (when data (if-let [charset (charset content-type)] - (-> (String. data charset) (parse-string)) - (-> (String. data) (parse-string))))) + (-> (String. data charset) (parse-string true)) + (-> (String. data) (parse-string true))))) (def application-json [application-json? application-json-encode application-json-decode]) diff --git a/test/com/mefesto/wabbitmq/test_content_type.clj b/test/com/mefesto/wabbitmq/test_content_type.clj index 6c9c47a..675cbcc 100644 --- a/test/com/mefesto/wabbitmq/test_content_type.clj +++ b/test/com/mefesto/wabbitmq/test_content_type.clj @@ -1,5 +1,5 @@ (ns com.mefesto.wabbitmq.test-content-type - (:use [clojure.contrib.json :only (json-str)] + (:use [cheshire.core :only (generate-string)] [clojure.test] [com.mefesto.wabbitmq.content-type]) (:import [java.util Arrays])) @@ -27,18 +27,18 @@ (is (false? (application-json? "application/other")))) (deftest application-json-encoding - (is (Arrays/equals (-> (json-str [1 2 3]) (.getBytes)) + (is (Arrays/equals (-> (generate-string [1 2 3]) (.getBytes)) (application-json-encode "application/json" [1 2 3]))) - (is (Arrays/equals (-> (json-str [1 2 3]) (.getBytes "utf16")) + (is (Arrays/equals (-> (generate-string [1 2 3]) (.getBytes "utf16")) (application-json-encode "application/json; charset=UTF-16" [1 2 3])))) (deftest application-json-decoding (is (= [1 2 3] (application-json-decode "application/json" - (-> (json-str [1 2 3]) (.getBytes))))) + (-> (generate-string [1 2 3]) (.getBytes))))) (is (= [1 2 3] (application-json-decode "application/json; charset=UTF-16" - (-> (json-str [1 2 3]) (.getBytes "utf16")))))) + (-> (generate-string [1 2 3]) (.getBytes "utf16")))))) (deftest application-clojure-supported? (is (true? (application-clojure? "application/clojure")))