Permalink
Browse files

A bit of re-org

  • Loading branch information...
1 parent 9b08f41 commit e02a9ae8dd1b6605db12c810f35a5144f4810325 @dakrone committed Nov 20, 2012
Showing with 26 additions and 1 deletion.
  1. +5 −0 src/cheshire/custom.clj
  2. +2 −0 src/cheshire/generate.clj
  3. +13 −1 test/cheshire/test/core.clj
  4. +6 −0 test/cheshire/test/custom.clj
View
@@ -14,6 +14,11 @@
JsonGenerator$Feature
JsonGenerationException JsonParser)))
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;; DEPRECATED, DO NOT USE ;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+
;; date format rebound for custom encoding
(def ^{:dynamic true :private true} *date-format*)
@@ -1,4 +1,5 @@
(ns cheshire.generate
+ "Namespace used to generate JSON from Clojure data structures."
(:import (com.fasterxml.jackson.core JsonGenerator JsonGenerationException)
(java.util Date Map List Set SimpleTimeZone UUID)
(java.sql Timestamp)
@@ -277,6 +278,7 @@
(extend clojure.lang.Associative
JSONable
{:to-json encode-map})
+
;; Utility methods to add and remove encoders
(defn add-encoder
"Provide an encoder for a type not handled by Cheshire.
@@ -2,9 +2,11 @@
(:use [clojure.test]
[clojure.java.io :only [file reader]])
(:require [cheshire.core :as json]
+ [cheshire.generate :as gen]
[cheshire.factory :as fact]
[cheshire.parse :as parse])
- (:import (java.io FileInputStream StringReader StringWriter
+ (:import (com.fasterxml.jackson.core JsonGenerationException)
+ (java.io FileInputStream StringReader StringWriter
BufferedReader BufferedWriter)
(java.sql Timestamp)
(java.util Date UUID)))
@@ -204,3 +206,13 @@
(is (= {"foo" "bar"} (json/decode "{\"foo\": \"bar\"}" nil)))
(is (= {"foo" "bar"} (json/decode "{\"foo\": \"bar\"}" false)))
(is (= {:foo "bar"} (json/decode "{\"foo\": \"bar\"}" true))))
+
+(deftest test-add-remove-encoder
+ (gen/remove-encoder java.net.URL)
+ (gen/add-encoder java.net.URL gen/encode-str)
+ (is (= "\"http://foo.com\""
+ (json/encode (java.net.URL. "http://foo.com"))))
+ (gen/remove-encoder java.net.URL)
+ (is (thrown? JsonGenerationException
+ (json/encode (java.net.URL. "http://foo.com")))))
+
@@ -1,4 +1,5 @@
(ns cheshire.test.custom
+ "DEPRECATED, kept here to ensure backward compatibility."
(:use [clojure.test]
[clojure.java.io :only [reader]])
(:require [cheshire.custom :as json] :reload
@@ -9,6 +10,11 @@
(java.sql Timestamp)
(java.util Date UUID)))
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;; DEPRECATED, DO NOT USE ;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+
;; Generally, all tests in here should use json/encode*, unless you
;; know what you're doing and what you're trying to test.

0 comments on commit e02a9ae

Please sign in to comment.