Permalink
Browse files

Migrate to Cheshire

  • Loading branch information...
1 parent d976839 commit 71e79a142091d3e1d7cb3cf1316408462ed50f6d @michaelklishin committed Sep 6, 2012
View
@@ -1,5 +1,10 @@
## Changes between Welle 1.2.0 and 1.3.0
+### Cheshire For JSON Serliazation
+
+Welle now uses (and depends on) [Cheshire](https://github.com/dakrone/cheshire) for JSON serialization.
+[clojure.data.json](https://github.com/clojure/data.json) is no longer a dependency.
+
### Clojure 1.4 By Default
Welle now depends on `org.clojure/clojure` version `1.4.0`. It is still compatible with Clojure 1.3 and if your `project.clj` depends
View
@@ -5,8 +5,8 @@
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.4.0"]
[com.basho.riak/riak-client "1.0.5"]
- [org.clojure/data.json "0.1.2"]
- [clojurewerkz/support "0.6.0"]
+ [cheshire "4.0.2"]
+ [clojurewerkz/support "0.7.0"]
[com.novemberain/validateur "1.2.0"]]
:source-paths ["src/clojure"]
:profiles {:1.3 {:dependencies [[org.clojure/clojure "1.3.0"]]}
@@ -1,5 +1,6 @@
(ns clojurewerkz.welle.conversion
- (:require [clojure.data.json :as json]
+ (:require [cheshire.custom :as json]
+ [cheshire.core :as json2]
[clojure.set :as cs]
[clojure.java.io :as io])
(:use [clojure.walk :only [stringify-keys]]
@@ -285,17 +286,17 @@
;; JSON
(defmethod serialize Constants/CTYPE_JSON
[value _]
- (json/json-str value))
+ (json/encode value))
(defmethod serialize Constants/CTYPE_JSON_UTF8
[value _]
- (json/json-str value))
+ (json/encode value))
;; a way to support GZip content encoding for both HTTP and PB interfaces.
(defmethod serialize "application/json+gzip"
[value _]
(with-open [out (ByteArrayOutputStream.)
gzip (GZIPOutputStream. out)
writer (PrintWriter. gzip)]
- (json/write-json value writer true)
+ (json2/generate-stream value writer)
(.flush writer)
(.finish gzip)
(.toByteArray out)))
@@ -326,21 +327,21 @@
;; JSON
(defmethod deserialize Constants/CTYPE_JSON
[value _]
- (json/read-json (String. ^bytes value)))
+ (json/parse-string (String. ^bytes value) true))
;; as of Riak Java client 1.1, this constant's value is "application/json;charset=UTF-8"
;; (no space between base content type and parameters). However, Riak returns content type *with*
;; the space so we have to cover both. Reported to Basho at https://github.com/basho/riak-java-client/issues/125.
;; MK.
(defmethod deserialize Constants/CTYPE_JSON_UTF8
[value _]
- (json/read-json (String. ^bytes value "UTF-8")))
+ (json/decode (String. ^bytes value "UTF-8") true))
(defmethod deserialize "application/json; charset=UTF-8"
[value _]
- (json/read-json (String. ^bytes value "UTF-8")))
+ (json/decode (String. ^bytes value "UTF-8") true))
(defmethod deserialize "application/json+gzip"
[value _]
(with-open [in (GZIPInputStream. (ByteArrayInputStream. ^bytes value))]
- (json/read-json (InputStreamReader. in "UTF-8"))))
+ (json/decode-stream (InputStreamReader. in "UTF-8") true)))
;; Clojure
(defmethod deserialize "application/clojure"
@@ -1,5 +1,5 @@
(ns clojurewerkz.welle.mr
- (:require [clojure.data.json :as json])
+ (:require [cheshire.custom :as json])
(:use clojurewerkz.welle.core)
(:import com.basho.riak.client.raw.query.MapReduceSpec))
@@ -11,5 +11,5 @@
(defn map-reduce
"Runs a map/reduce query"
[query]
- (let [result (.mapReduce *riak-client* (MapReduceSpec. (json/json-str query)))]
- (json/read-json (.getResultRaw result))))
+ (let [result (.mapReduce *riak-client* (MapReduceSpec. (json/encode query)))]
+ (json/decode (.getResultRaw result) true)))
@@ -1,7 +1,6 @@
(ns clojurewerkz.welle.ring.session-store
(:require [ring.middleware.session.store :as ringstore]
- [clojurewerkz.welle.kv :as kv]
- clojurewerkz.support.json)
+ [clojurewerkz.welle.kv :as kv])
(:import [java.util UUID Date]
com.basho.riak.client.http.util.Constants))

0 comments on commit 71e79a1

Please sign in to comment.