Permalink
Browse files

Support transparent SMILE serialization

  • Loading branch information...
michaelklishin committed Sep 7, 2012
1 parent 6fdee15 commit 279e9ac66b8a67ed97aff0bf496af53c94580446
Showing with 47 additions and 6 deletions.
  1. +10 −0 ChangeLog.md
  2. +18 −0 src/clojure/clojurewerkz/welle/conversion.clj
  3. +19 −6 test/clojurewerkz/welle/test/kv_test.clj
View
@@ -1,5 +1,13 @@
## Changes between Welle 1.2.0 and 1.3.0
+### Support for SMILE
+
+Welle now provides transparent serialization and deserialization support for SMILE, just like it has for
+JSON, compressed data and Clojure reader. To use it, set `:content-type` of an value to `"application/jackson-smile"`.
+
+SMILE serialization can be extended to custom data types, see [Cheshire documentation](https://github.com/dakrone/cheshire) for
+more information.
+
### Cheshire For JSON Serliazation
Welle now uses (and depends on) [Cheshire](https://github.com/dakrone/cheshire) for JSON serialization.
@@ -18,6 +26,8 @@ We encourage all users to upgrade to 1.4, it is a drop-in replacement for the ma
machines), optimistically assuming there will be no siblings for each one.
+
+
## Changes between Welle 1.1.0 and 1.2.0
### Validateur 1.2.0
@@ -301,6 +301,15 @@
(.finish gzip)
(.toByteArray out)))
+;; Clojure
+(defmethod serialize "application/jackson-smile"
+ [value _]
+ (json/generate-smile value))
+
+(defmethod serialize "application/smile"
+ [value _]
+ (json/generate-smile value))
+
;; Clojure
(defmethod serialize "application/clojure"
[value _]
@@ -343,6 +352,15 @@
(with-open [in (GZIPInputStream. (ByteArrayInputStream. ^bytes value))]
(json/decode-stream (InputStreamReader. in "UTF-8") true)))
+;; SMILE (binary JSON)
+(defmethod deserialize "application/jackson-smile"
+ [value _]
+ (json/decode-smile value true))
+
+(defmethod deserialize "application/smile"
+ [value _]
+ (json/decode-smile value true))
+
;; Clojure
(defmethod deserialize "application/clojure"
[value _]
@@ -68,7 +68,7 @@
(is (empty? stored))
(is (= Constants/CTYPE_JSON (:content-type fetched)))
(is (= {} (:metadata fetched)))
- (is (= {:kind "Data store", :name "Riak", :influenced-by ["Dynamo"]} (:value fetched)))
+ (is (= {:kind "Data store" :name "Riak" :influenced-by ["Dynamo"]} (:value fetched)))
(is-riak-object fetched)
(drain bucket-name)))
@@ -80,9 +80,22 @@
v {:name "Riak" :kind "Data store" :influenced-by #{"Dynamo"}}
stored (kv/store bucket-name k v :content-type Constants/CTYPE_JSON_UTF8)
[fetched] (kv/fetch bucket-name k)]
- ;; cannot use constant value here, see https://github.com/basho/riak-java-client/issues/125
+ ;; cannot use constant value here see https://github.com/basho/riak-java-client/issues/125
(is (= "application/json; charset=UTF-8" (:content-type fetched)))
- (is (= {:kind "Data store", :name "Riak", :influenced-by ["Dynamo"]} (:value fetched)))
+ (is (= {:kind "Data store" :name "Riak" :influenced-by ["Dynamo"]} (:value fetched)))
+ (drain bucket-name)))
+
+
+(deftest test-basic-store-with-jackson-smile-content-type
+ (let [bucket-name "clojurewerkz.welle.kv"
+ bucket (wb/update bucket-name)
+ ct "application/jackson-smile"
+ k "store-as-jackson-smile"
+ v {:name "Riak" :kind "Data store" :influenced-by #{"Dynamo"}}
+ stored (kv/store bucket-name k v :content-type ct)
+ [fetched] (kv/fetch bucket-name k)]
+ (is (= ct (:content-type fetched)))
+ (is (= {:kind "Data store" :name "Riak" :influenced-by ["Dynamo"]} (:value fetched)))
(drain bucket-name)))
@@ -95,7 +108,7 @@
ct "application/clojure"
stored (kv/store bucket-name k v :content-type ct)
fetched (kv/fetch-one bucket-name k)]
- ;; cannot use constant value here, see https://github.com/basho/riak-java-client/issues/125
+ ;; cannot use constant value here see https://github.com/basho/riak-java-client/issues/125
(is (= ct (:content-type fetched)))
(is (= v (:value fetched)))
(drain bucket-name)))
@@ -114,7 +127,7 @@
(is (empty? stored))
(is (= ct (:content-type fetched)))
(is (= {} (:metadata fetched)))
- (is (= {:kind "Data store", :name "Riak", :influenced-by ["Dynamo"]} (:value fetched)))
+ (is (= {:kind "Data store" :name "Riak" :influenced-by ["Dynamo"]} (:value fetched)))
(is-riak-object fetched)
(drain bucket-name)))
@@ -133,7 +146,7 @@
stored (kv/store bucket-name k v :content-type Constants/CTYPE_TEXT_UTF8 :metadata metadata)
[fetched] (kv/fetch bucket-name k)]
(is (= Constants/CTYPE_TEXT_UTF8 (:content-type fetched)))
- (is (= {"author" "Joe", "density" "5"} (:metadata fetched)))
+ (is (= {"author" "Joe" "density" "5"} (:metadata fetched)))
(is (= v (:value fetched)))
(is-riak-object fetched)
(drain bucket-name)))

0 comments on commit 279e9ac

Please sign in to comment.