Skip to content

Commit

Permalink
Merge branch 'cheshire'
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelklishin committed Sep 6, 2012
2 parents d976839 + 71e79a1 commit 6fdee15
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.md
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions project.clj
Expand Up @@ -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"]]}
Expand Down
17 changes: 9 additions & 8 deletions src/clojure/clojurewerkz/welle/conversion.clj
@@ -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]]
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions src/clojure/clojurewerkz/welle/mr.clj
@@ -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))

Expand All @@ -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)))
3 changes: 1 addition & 2 deletions src/clojure/clojurewerkz/welle/ring/session_store.clj
@@ -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))

Expand Down

0 comments on commit 6fdee15

Please sign in to comment.