diff --git a/src/cheshire/generate.clj b/src/cheshire/generate.clj index e0739928..f3e7fb04 100644 --- a/src/cheshire/generate.clj +++ b/src/cheshire/generate.clj @@ -8,7 +8,7 @@ (clojure.lang IPersistentCollection Keyword Ratio Symbol))) ;; date format rebound for custom encoding -(def ^{:dynamic true :private true} *date-format* "yyyy-MM-dd'T'HH:mm:ssZ") +(def ^{:dynamic true :private true} *date-format*) (defmacro tag ([obj] diff --git a/src/cheshire/parse.clj b/src/cheshire/parse.clj index 01a8a4f8..91411efd 100644 --- a/src/cheshire/parse.clj +++ b/src/cheshire/parse.clj @@ -8,20 +8,9 @@ :dynamic true} *use-bigdecimals?* false) -(def ^{:dynamic true} *valid-json-only* false) - (defmacro ^:private tag ([obj] - `(vary-meta ~obj assoc :tag `JsonParser))) - -(defmacro valid [parsed] - `(if *valid-json-only* - (let [valid-json?# (try (nil? (.nextToken ~'jp)) - (catch Exception _# false))] - (if-not valid-json?# - (throw (Exception. "Invalid json")) - ~parsed)) - ~parsed)) + `(vary-meta ~obj assoc :tag `JsonParser))) (definline parse-object [^JsonParser jp key-fn bd? array-coerce-fn] (let [jp (tag jp)] @@ -87,24 +76,23 @@ (str "Cannot parse " (pr-str (.getCurrentToken jp))))))) (defn parse-strict [^JsonParser jp key-fn eof array-coerce-fn] - (let [key-fn (or (if (identical? key-fn true) keyword key-fn) identity) - _ (.nextToken jp) - parsed (condp identical? (.getCurrentToken jp) - nil - eof - (parse* jp key-fn *use-bigdecimals?* array-coerce-fn))] - (valid parsed))) + (let [key-fn (or (if (identical? key-fn true) keyword key-fn) identity)] + (.nextToken jp) + (condp identical? (.getCurrentToken jp) + nil + eof + (parse* jp key-fn *use-bigdecimals?* array-coerce-fn)))) (defn parse [^JsonParser jp key-fn eof array-coerce-fn] - (let [key-fn (or (if (and (instance? Boolean key-fn) key-fn) keyword key-fn) identity) - _ (.nextToken jp) - parsed (condp identical? (.getCurrentToken jp) - nil - eof + (let [key-fn (or (if (and (instance? Boolean key-fn) key-fn) keyword key-fn) identity)] + (.nextToken jp) + (condp identical? (.getCurrentToken jp) + nil + eof + + JsonToken/START_ARRAY + (do + (.nextToken jp) + (lazily-parse-array jp key-fn *use-bigdecimals?* array-coerce-fn)) - JsonToken/START_ARRAY - (do - (.nextToken jp) - (lazily-parse-array jp key-fn *use-bigdecimals?* array-coerce-fn)) - (parse* jp key-fn *use-bigdecimals?* array-coerce-fn))] - (valid parsed))) + (parse* jp key-fn *use-bigdecimals?* array-coerce-fn))))