[Git][clojure-team/cheshire-clojure][upstream] New upstream version 5.11.0

Jérôme Charaoui (@lavamind) gitlab at salsa.debian.org
Sun Feb 5 05:05:34 GMT 2023



Jérôme Charaoui pushed to branch upstream at Debian Clojure Maintainers / cheshire-clojure


Commits:
d2a87864 by Jérôme Charaoui at 2023-02-04T21:35:37-05:00
New upstream version 5.11.0
- - - - -


15 changed files:

- .travis.yml
- ChangeLog.md
- README.md
- project.clj
- src/cheshire/core.clj
- src/cheshire/custom.clj
- + src/cheshire/exact.clj
- src/cheshire/factory.clj
- src/cheshire/generate.clj
- src/cheshire/generate_seq.clj
- src/cheshire/parse.clj
- + src/data_readers.clj
- src/java/cheshire/prettyprint/CustomPrettyPrinter.java
- test/cheshire/test/core.clj
- test/cheshire/test/custom.clj


Changes:

=====================================
.travis.yml
=====================================
@@ -1,10 +1,11 @@
 language: clojure
-lein: lein2
-script: lein2 all test :all
+lein: lein
+script: lein all test :all
 branches:
   only:
     - master
 jdk:
-  - oraclejdk8
-  - openjdk7
-  - oraclejdk7
+  - openjdk8
+  - openjdk9
+  - openjdk10
+  - openjdk11


=====================================
ChangeLog.md
=====================================
@@ -1,3 +1,21 @@
+## Changes between Cheshire 5.8.1 and 5.9.0
+
+* Add `parse-stream-strict` to parse streams strictly rather than lazily
+* Bump Jackson dependencies to 2.9.9
+* Chunk size for lazy seqs is now configurable
+
+## Changes between Cheshire 5.8.0 and 5.8.1
+
+* Add `:quote-field-names` parameter to control quoting field names in encoding
+
+## Changes between Cheshire 5.7.2 and 5.8.0
+
+* Fix type hints for un-imported classes
+* Update Jackson dependencies to mitigate vulnerability https://github.com/FasterXML/jackson-databind/issues/1599
+* Correct spelling in documentation
+* Add `cheshire.exact` namespace for exactly-once decoding
+* Bump Jackson dependencies to 2.9.0
+
 ## Changes between Cheshire 5.6.3 and 5.6.2
 
 * Fix float coercion when encoding


=====================================
README.md
=====================================
@@ -1,6 +1,6 @@
 # Cheshire
 
-<img src="http://dakrone.github.com/cheshire/cheshire_small.jpg"
+<img src="https://dakrone.github.io/cheshire/cheshire_small.jpg"
 title=":)" align="left" padding="5px" />
 <small>
 'Cheshire Puss,' she began, rather timidly, as she did not at all know
@@ -24,8 +24,10 @@ Cheshire is fast JSON encoding, based off of clj-json and
 clojure-json, with additional features like Date/UUID/Set/Symbol
 encoding and SMILE support.
 
-[Clojure code with docs](http://dakrone.github.com/cheshire/)
 
+[Clojure code with docs](http://dakrone.github.io/cheshire/)
+
+[![Clojars Project](https://img.shields.io/clojars/v/cheshire.svg)](https://clojars.org/cheshire)
 [![Continuous Integration status](https://secure.travis-ci.org/dakrone/cheshire.png)](http://travis-ci.org/dakrone/cheshire)
 
 ## Why?
@@ -38,9 +40,9 @@ encoders.
 ## Usage
 
 ```clojure
-[cheshire "5.7.1"]
+[cheshire "5.11.0"]
 
-;; Cheshire v5.7.1 uses Jackson 2.8.6
+;; Cheshire v5.11.0 uses Jackson 2.13.3
 
 ;; In your ns statement:
 (ns my.ns
@@ -227,7 +229,7 @@ Cheshire encoding supports:
 - booleans
 - keywords (qualified and unqualified)
 - numbers (Integer, Long, BigInteger, BigInt, Double, Float, Ratio,
-  Short, Byte, primatives)
+  Short, Byte, primitives)
 - clojure.lang.PersistentQueue
 
 ### Java classes
@@ -311,9 +313,9 @@ It's experimental, like the name says. Based on [Tigris](http://github.com/dakro
 
 ## Advanced customization for factories
 See
-[this](http://fasterxml.github.com/jackson-core/javadoc/2.1.1/com/fasterxml/jackson/core/JsonFactory.Feature.html)
+[this](http://fasterxml.github.com/jackson-core/javadoc/2.10/com/fasterxml/jackson/core/JsonFactory.Feature.html)
 and
-[this](http://fasterxml.github.com/jackson-core/javadoc/2.1.1/com/fasterxml/jackson/core/JsonParser.Feature.html)
+[this](http://fasterxml.github.com/jackson-core/javadoc/2.10/com/fasterxml/jackson/core/JsonParser.Feature.html)
 for a list of features that can be customized if desired. A custom
 factory can be used like so:
 


=====================================
project.clj
=====================================
@@ -1,28 +1,29 @@
-(defproject cheshire "5.7.1"
+(defproject cheshire "5.11.0"
   :description "JSON and JSON SMILE encoding, fast."
   :url "https://github.com/dakrone/cheshire"
   :license {:name "The MIT License"
             :url "http://opensource.org/licenses/MIT"
             :distribution :repo}
   :global-vars {*warn-on-reflection* false}
-  :dependencies [[com.fasterxml.jackson.core/jackson-core "2.8.6"]
-                 [com.fasterxml.jackson.dataformat/jackson-dataformat-smile "2.8.6"]
-                 [com.fasterxml.jackson.dataformat/jackson-dataformat-cbor "2.8.6"]
-                 [tigris "0.1.1"]]
-  :profiles {:dev {:dependencies [[org.clojure/clojure "1.8.0"]
-                                  [org.clojure/test.generative "0.1.4"]]}
-             :1.3 {:dependencies [[org.clojure/clojure "1.3.0"]]}
-             :1.4 {:dependencies [[org.clojure/clojure "1.4.0"]]}
-             :1.5 {:dependencies [[org.clojure/clojure "1.5.1"]]}
+  :dependencies [[com.fasterxml.jackson.core/jackson-core "2.13.3"]
+                 [com.fasterxml.jackson.dataformat/jackson-dataformat-smile "2.13.3"
+                  :exclusions [com.fasterxml.jackson.core/jackson-databind]]
+                 [com.fasterxml.jackson.dataformat/jackson-dataformat-cbor "2.13.3"
+                  :exclusions [com.fasterxml.jackson.core/jackson-databind]]
+                 [tigris "0.1.2"]]
+  :profiles {:dev {:dependencies [[org.clojure/clojure "1.11.1"]
+                                  [org.clojure/test.generative "0.1.4"]
+                                  [org.clojure/tools.namespace "0.3.1"]]}
              :1.7 {:dependencies [[org.clojure/clojure "1.7.0"]]}
              :1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]}
-             :1.9 {:dependencies [[org.clojure/clojure "1.9.0-alpha7"]]}
+             :1.9 {:dependencies [[org.clojure/clojure "1.9.0"]]}
+             :1.10 {:dependencies [[org.clojure/clojure "1.10.3"]]}
              :benchmark {:test-paths ["benchmarks"]
                          :jvm-opts ^:replace ["-Xms1g" "-Xmx1g" "-server"]
-                         :dependencies [[criterium "0.4.4"]
+                         :dependencies [[criterium "0.4.6"]
                                         [org.clojure/data.json "0.2.6"]
                                         [clj-json "0.5.3"]]}}
-  :aliases {"all" ["with-profile" "dev,1.3:dev,1.4:dev,1.5:dev,1.7:dev,1.8:dev,1.9:dev"]
+  :aliases {"all" ["with-profile" "dev,1.7:dev,1.8:dev,1.9:dev,1.10:dev"]
             "benchmark" ["with-profile" "dev,benchmark" "test"]
             "pretty-bench" ["with-profile" "dev,benchmark" "test" ":only"
                           "cheshire.test.benchmark/t-bench-pretty"]
@@ -32,11 +33,12 @@
                                    (not (:generative %)))
                    :generative :generative
                    :all (constantly true)}
-  :plugins [[codox "0.6.3"]]
+  :plugins [[codox "0.6.3"]
+            [lein-ancient "0.6.15"]]
   :java-source-paths ["src/java"]
   :jvm-opts ["-Xmx512M"
 ;;             "-XX:+PrintCompilation"
 ;;             "-XX:+UnlockDiagnosticVMOptions"
 ;;             "-XX:+PrintInlining"
              ]
-  :javac-options ["-target" "1.6" "-source" "1.6" "-Xlint:-options"])
+  :javac-options ["-target" "1.7" "-source" "1.7" "-Xlint:-options"])


=====================================
src/cheshire/core.clj
=====================================
@@ -7,6 +7,7 @@
   (:import (com.fasterxml.jackson.core JsonParser JsonFactory
                                        JsonGenerator PrettyPrinter
                                        JsonGenerator$Feature)
+           (com.fasterxml.jackson.dataformat.cbor CBORFactory)
            (com.fasterxml.jackson.dataformat.smile SmileFactory)
            (cheshire.prettyprint CustomPrettyPrinter)
            (java.io StringWriter StringReader BufferedReader BufferedWriter
@@ -109,8 +110,9 @@
      (.flush generator)
      writer)))
 
-(defn create-generator [writer]
+(defn create-generator
   "Returns JsonGenerator for given writer."
+  [writer]
   (.createGenerator
    ^JsonFactory (or factory/*json-factory*
                     factory/json-factory)
@@ -119,11 +121,12 @@
 (def ^:dynamic ^JsonGenerator *generator*)
 (def ^:dynamic *opt-map*)
 
-(defmacro with-writer [[writer opt-map] & body]
+(defmacro with-writer
   "Start writing for series objects using the same json generator.
    Takes writer and options map as arguments.
    Expects its body as sequence of write calls.
    Returns a given writer."
+  [[writer opt-map] & body]
   `(let [c-wr# ~writer]
      (binding [*generator* (create-generator c-wr#)
                *opt-map* ~opt-map]
@@ -225,7 +228,7 @@
      (parse/parse-strict
       (.createParser ^JsonFactory (or factory/*json-factory*
                                       factory/json-factory)
-                     ^Writer (StringReader. string))
+                     ^Reader (StringReader. string))
       key-fn nil array-coerce-fn))))
 
 (defn parse-stream
@@ -252,6 +255,26 @@
                      ^Reader rdr)
       key-fn nil array-coerce-fn))))
 
+(defn parse-stream-strict
+  "Returns the Clojure object corresponding to the given reader, reader must
+  implement BufferedReader. An optional key-fn argument can be either true (to
+  coerce keys to keywords),false to leave them as strings, or a function to
+  provide custom coercion.
+
+  The array-coerce-fn is an optional function taking the name of an array field,
+  and returning the collection to be used for array values.
+
+  Does not lazily parse top-level arrays."
+  ([rdr] (parse-stream-strict rdr nil nil))
+  ([rdr key-fn] (parse-stream-strict rdr key-fn nil))
+  ([^BufferedReader rdr key-fn array-coerce-fn]
+   (when rdr
+     (parse/parse-strict
+       (.createParser ^JsonFactory (or factory/*json-factory*
+                                       factory/json-factory)
+                      ^Reader rdr)
+       key-fn nil array-coerce-fn))))
+
 (defn parse-smile
   "Returns the Clojure object corresponding to the given SMILE-encoded bytes.
   An optional key-fn argument can be either true (to coerce keys to keywords),


=====================================
src/cheshire/custom.clj
=====================================
@@ -155,8 +155,7 @@
   "Encode a seq to the json generator."
   [s ^JsonGenerator jg]
   (.writeStartArray jg)
-  (doseq [i s]
-    (to-json i jg))
+  (reduce (fn [jg i] (to-json i jg) jg) jg s)
   (.writeEndArray jg))
 
 (defn encode-date
@@ -182,13 +181,17 @@
   "Encode a clojure map to the json generator."
   [^clojure.lang.IPersistentMap m ^JsonGenerator jg]
   (.writeStartObject jg)
-  (doseq [[k v] m]
-    (.writeFieldName jg (if (instance? clojure.lang.Keyword k)
-                          (if-let [ns (namespace k)]
-                            (str ns "/" (name k))
-                            (name k))
-                          (str k)))
-    (to-json v jg))
+  (reduce (fn [^JsonGenerator jg kv]
+            (let [k (key kv)
+                  v (val kv)]
+              (.writeFieldName jg (if (instance? clojure.lang.Keyword k)
+                                    (if-let [ns (namespace k)]
+                                      (str ns "/" (name k))
+                                      (name k))
+                                    (str k)))
+              (to-json v jg)
+              jg))
+          jg m)
   (.writeEndObject jg))
 
 (defn encode-symbol


=====================================
src/cheshire/exact.clj
=====================================
@@ -0,0 +1,43 @@
+(ns cheshire.exact
+  (:require [cheshire.factory :as factory]
+            [cheshire.parse :as parse]
+            [cheshire.core :as core])
+  (:import (java.io StringReader Reader BufferedReader
+                    Writer)
+           (com.fasterxml.jackson.core JsonFactory)))
+
+(defn- exact-parse [jp parsed]
+  (let [valid-json? (try (nil? (.nextToken jp))
+                         (catch Exception _ false))]
+    (if valid-json?
+      parsed
+      (throw
+       (IllegalArgumentException.
+        "Invalid JSON, expected exactly one parseable object but multiple objects were found")))))
+
+(defn parse-string
+  "Like cheshire.core/parse-string
+  but with only valid json string"
+  ([string] (parse-string string nil nil))
+  ([string key-fn] (parse-string string key-fn nil))
+  ([^String string key-fn array-coerce-fn]
+   (when string
+     (let [jp (.createParser ^JsonFactory (or factory/*json-factory*
+                                              factory/json-factory)
+                             ^Reader (StringReader. string))]
+       (exact-parse jp (parse/parse jp key-fn nil array-coerce-fn))))))
+
+(defn parse-string-strict
+  ([string] (parse-string-strict string nil nil))
+  ([string key-fn] (parse-string-strict string key-fn nil))
+  ([^String string key-fn array-coerce-fn]
+   (when string
+     (let [jp (.createParser ^JsonFactory (or factory/*json-factory*
+                                              factory/json-factory)
+                             ^Writer (StringReader. string))]
+       (exact-parse jp (parse/parse-strict jp key-fn nil array-coerce-fn))))))
+
+(def decode parse-string)
+(core/copy-arglists decode parse-string)
+(def decode-strict parse-string-strict)
+(core/copy-arglists decode-strict parse-string-strict)


=====================================
src/cheshire/factory.clj
=====================================
@@ -4,7 +4,8 @@
   (:import (com.fasterxml.jackson.dataformat.smile SmileFactory)
            (com.fasterxml.jackson.dataformat.cbor CBORFactory)
            (com.fasterxml.jackson.core JsonFactory JsonFactory$Feature
-                                       JsonParser$Feature)))
+                                       JsonParser$Feature
+                                       JsonGenerator$Feature)))
 
 ;; default date format used to JSON-encode Date objects
 (def default-date-format "yyyy-MM-dd'T'HH:mm:ss'Z'")
@@ -19,7 +20,9 @@
    :allow-numeric-leading-zeros false
    :allow-non-numeric-numbers false
    :intern-field-names false
-   :canonicalize-field-names false})
+   :canonicalize-field-names false
+   :quote-field-names true
+   :strict-duplicate-detection false})
 
 ;; Factory objects that are needed to do the encoding and decoding
 (defn make-json-factory
@@ -42,10 +45,14 @@
                   (boolean (:allow-numeric-leading-zeros opts)))
       (.configure JsonParser$Feature/ALLOW_NON_NUMERIC_NUMBERS
                   (boolean (:allow-non-numeric-numbers opts)))
+      (.configure JsonParser$Feature/STRICT_DUPLICATE_DETECTION
+                  (boolean (:strict-duplicate-detection opts)))
       (.configure JsonFactory$Feature/INTERN_FIELD_NAMES
                   (boolean (:intern-field-names opts)))
       (.configure JsonFactory$Feature/CANONICALIZE_FIELD_NAMES
-                  (boolean (:canonicalize-field-names opts))))))
+                  (boolean (:canonicalize-field-names opts)))
+      (.configure JsonGenerator$Feature/QUOTE_FIELD_NAMES
+                  (boolean (:quote-field-names opts))))))
 
 (defn make-smile-factory
   ^SmileFactory [opts]
@@ -70,7 +77,9 @@
       (.configure JsonFactory$Feature/INTERN_FIELD_NAMES
                   (boolean (:intern-field-names opts)))
       (.configure JsonFactory$Feature/CANONICALIZE_FIELD_NAMES
-                  (boolean (:canonicalize-field-names opts))))))
+                  (boolean (:canonicalize-field-names opts)))
+      (.configure JsonGenerator$Feature/QUOTE_FIELD_NAMES
+                  (boolean (:quote-field-names opts))))))
 
 (defn make-cbor-factory
   ^CBORFactory [opts]
@@ -95,7 +104,9 @@
       (.configure JsonFactory$Feature/INTERN_FIELD_NAMES
                   (boolean (:intern-field-names opts)))
       (.configure JsonFactory$Feature/CANONICALIZE_FIELD_NAMES
-                  (boolean (:canonicalize-field-names opts))))))
+                  (boolean (:canonicalize-field-names opts)))
+      (.configure JsonGenerator$Feature/QUOTE_FIELD_NAMES
+                  (boolean (:quote-field-names opts))))))
 
 (defonce ^JsonFactory json-factory (make-json-factory default-factory-options))
 (defonce ^SmileFactory smile-factory


=====================================
src/cheshire/generate.clj
=====================================
@@ -61,13 +61,15 @@
   (let [jg (tag jg)]
     `(do
        (.writeStartObject ~jg)
-       (doseq [m# ~obj]
-         (let [k# (key m#)
-               v# (val m#)]
-           (.writeFieldName ~jg (if (keyword? k#)
-                                  (.substring (str k#) 1)
-                                  (str k#)))
-           (generate ~jg v# ~date-format ~e nil)))
+       (reduce (fn [^JsonGenerator jg# kv#]
+                 (let [k# (key kv#)
+                       v# (val kv#)]
+                   (.writeFieldName jg# (if (keyword? k#)
+                                          (.substring (str k#) 1)
+                                          (str k#)))
+                   (generate jg# v# ~date-format ~e nil)
+                   jg#))
+               ~jg ~obj)
        (.writeEndObject ~jg))))
 
 (definline generate-key-fn-map
@@ -77,14 +79,16 @@
         jg (tag jg)]
     `(do
        (.writeStartObject ~jg)
-       (doseq [m# ~obj]
-         (let [~k (key m#)
-               v# (val m#)
-               ^String name# (if (keyword? ~k)
-                               (~key-fn ~k)
-                               (str ~k))]
-           (.writeFieldName ~jg name#)
-           (generate ~jg v# ~date-format ~e ~key-fn)))
+       (reduce (fn [^JsonGenerator jg# kv#]
+                 (let [~k (key kv#)
+                       v# (val kv#)
+                       ^String name# (if (keyword? ~k)
+                                       (~key-fn ~k)
+                                       (str ~k))]
+                   (.writeFieldName jg# name#)
+                   (generate jg# v# ~date-format ~e ~key-fn)
+                   jg#))
+               ~jg ~obj)
        (.writeEndObject ~jg))))
 
 (definline generate-map
@@ -98,8 +102,7 @@
   (let [jg (tag jg)]
     `(do
        (.writeStartArray ~jg)
-       (doseq [item# ~obj]
-         (generate ~jg item# ~date-format ~e ~key-fn))
+       (reduce (fn [jg# item#] (generate jg# item# ~date-format ~e ~key-fn) jg#) ~jg ~obj)
        (.writeEndArray ~jg))))
 
 (defmacro i?
@@ -188,8 +191,7 @@
   "Encode a seq to the json generator."
   [s ^JsonGenerator jg]
   (.writeStartArray jg)
-  (doseq [i s]
-    (generate jg i *date-format* nil nil))
+  (reduce (fn [jg i] (generate jg i *date-format* nil nil) jg) jg s)
   (.writeEndArray jg))
 
 (defn encode-date
@@ -215,13 +217,17 @@
   "Encode a clojure map to the json generator."
   [^clojure.lang.IPersistentMap m ^JsonGenerator jg]
   (.writeStartObject jg)
-  (doseq [[k v] m]
-    (.writeFieldName jg (if (instance? clojure.lang.Keyword k)
-                          (if-let [ns (namespace k)]
-                            (str ns "/" (name k))
-                            (name k))
-                          (str k)))
-    (generate jg v *date-format* nil nil))
+  (reduce (fn [^JsonGenerator jg kv]
+            (let [k (key kv)
+                  v (val kv)]
+              (.writeFieldName jg (if (instance? clojure.lang.Keyword k)
+                                    (if-let [ns (namespace k)]
+                                      (str ns "/" (name k))
+                                      (name k))
+                                    (str k)))
+              (generate jg v *date-format* nil nil)
+              jg))
+          jg m)
   (.writeEndObject jg))
 
 (defn encode-symbol


=====================================
src/cheshire/generate_seq.clj
=====================================
@@ -35,16 +35,18 @@
   (let [jg (tag jg)]
     `(do
        (write-start-object ~jg ~wholeness)
-       (doseq [m# ~obj]
-         (let [k# (key m#)
-               v# (val m#)]
-           (.writeFieldName ~jg (if (keyword? k#)
-                                  (.substring (str k#) 1)
-                                  (str k#)))
-           (generate ~jg v# ~date-format ~e nil
-                     :wholeness (if (= ~wholeness :start-inner)
-                                  :start
-                                  :all))))
+       (reduce (fn [^JsonGenerator jg# kv#]
+                 (let [k# (key kv#)
+                       v# (val kv#)]
+                   (.writeFieldName jg# (if (keyword? k#)
+                                          (.substring (str k#) 1)
+                                          (str k#)))
+                   (generate jg# v# ~date-format ~e nil
+                             :wholeness (if (= ~wholeness :start-inner)
+                                          :start
+                                          :all))
+                   jg#))
+               ~jg ~obj)
        (write-end-object ~jg ~wholeness))))
 
 (definline generate-key-fn-map
@@ -55,17 +57,19 @@
         jg (tag jg)]
     `(do
        (write-start-object ~jg ~wholeness)
-       (doseq [m# ~obj]
-         (let [~k (key m#)
-               v# (val m#)
-               ^String name# (if (keyword? ~k)
-                               (~key-fn ~k)
-                               (str ~k))]
-           (.writeFieldName ~jg name#)
-           (generate ~jg v# ~date-format ~e ~key-fn
-                     :wholeness (if (= ~wholeness :start-inner)
-                                  :start
-                                  :all))))
+       (reduce (fn [^JsonGenerator jg# kv#]
+                 (let [~k (key kv#)
+                       v# (val kv#)
+                       ^String name# (if (keyword? ~k)
+                                       (~key-fn ~k)
+                                       (str ~k))]
+                   (.writeFieldName jg# name#)
+                   (generate jg# v# ~date-format ~e ~key-fn
+                             :wholeness (if (= ~wholeness :start-inner)
+                                          :start
+                                          :all))
+                   jg#))
+               ~jg ~obj)
        (write-end-object ~jg ~wholeness))))
 
 (definline generate-map
@@ -80,11 +84,13 @@
   (let [jg (tag jg)]
     `(do
        (write-start-array ~jg ~wholeness)
-       (doseq [item# ~obj]
-         (generate ~jg item# ~date-format ~e ~key-fn
-                   :wholeness (if (= ~wholeness :start-inner)
-                                :start
-                                :all)))
+       (reduce (fn [jg# item#]
+                 (generate jg# item# ~date-format ~e ~key-fn
+                           :wholeness (if (= ~wholeness :start-inner)
+                                        :start
+                                        :all))
+                 jg#)
+               ~jg ~obj)
        (write-end-array ~jg ~wholeness))))
 
 (defn generate [^JsonGenerator jg obj ^String date-format


=====================================
src/cheshire/parse.clj
=====================================
@@ -3,6 +3,8 @@
 
 (declare parse*)
 
+(def ^:dynamic *chunk-size* 32)
+
 (def ^{:doc "Flag to determine whether float values should be returned as
              BigDecimals to retain precision. Defaults to false."
        :dynamic true}
@@ -45,14 +47,14 @@
 
 (defn lazily-parse-array [^JsonParser jp key-fn bd? array-coerce-fn]
   (lazy-seq
-   (loop [chunk-idx 0, buf (chunk-buffer 32)]
+   (loop [chunk-idx 0, buf (chunk-buffer *chunk-size*)]
      (if (identical? (.getCurrentToken jp) JsonToken/END_ARRAY)
        (chunk-cons (chunk buf) nil)
        (do
          (chunk-append buf (parse* jp key-fn bd? array-coerce-fn))
          (.nextToken jp)
          (let [chunk-idx* (unchecked-inc chunk-idx)]
-           (if (< chunk-idx* 32)
+           (if (< chunk-idx* *chunk-size*)
              (recur chunk-idx* buf)
              (chunk-cons
               (chunk buf)


=====================================
src/data_readers.clj
=====================================
@@ -0,0 +1 @@
+{cheshire/json cheshire.core/generate-string}


=====================================
src/java/cheshire/prettyprint/CustomPrettyPrinter.java
=====================================
@@ -49,6 +49,8 @@ public class CustomPrettyPrinter extends DefaultPrettyPrinter {
         }
         if (indentObjects) {
             this.indentObjectsWith(indenter);
+        } else {
+            this.indentObjectsWith(new DefaultPrettyPrinter.FixedSpaceIndenter());
         }
         return this;
     }


=====================================
test/cheshire/test/core.clj
=====================================
@@ -2,10 +2,12 @@
   (:use [clojure.test]
         [clojure.java.io :only [file reader]])
   (:require [cheshire.core :as json]
+            [cheshire.exact :as json-exact]
             [cheshire.generate :as gen]
             [cheshire.factory :as fact]
             [cheshire.parse :as parse])
-  (:import (com.fasterxml.jackson.core JsonGenerationException)
+  (:import (com.fasterxml.jackson.core JsonGenerationException
+                                       JsonParseException)
            (java.io FileInputStream StringReader StringWriter
                     BufferedReader BufferedWriter)
            (java.sql Timestamp)
@@ -148,16 +150,23 @@
   (is (= "{\"foo\":\"a\"}" (json/encode {:foo \a}))))
 
 (deftest test-streams
-  (is (= {"foo" "bar"}
-         (json/parse-stream
-          (BufferedReader. (StringReader. "{\"foo\":\"bar\"}\n")))))
-  (let [sw (StringWriter.)
-        bw (BufferedWriter. sw)]
-    (json/generate-stream {"foo" "bar"} bw)
-    (is (= "{\"foo\":\"bar\"}" (.toString sw))))
-  (is (= {(keyword "foo baz") "bar"}
-         (with-open [rdr (StringReader. "{\"foo baz\":\"bar\"}\n")]
-           (json/parse-stream rdr true)))))
+  (testing "parse-stream"
+    (are [parsed parse parsee] (= parsed
+                                  (parse (BufferedReader. (StringReader. parsee))))
+      {"foo" "bar"} json/parse-stream "{\"foo\":\"bar\"}\n"
+      {"foo" "bar"} json/parse-stream-strict "{\"foo\":\"bar\"}\n")
+
+    (are [parsed parse parsee] (= parsed
+                                  (with-open [rdr (StringReader. parsee)]
+                                    (parse rdr true)))
+      {(keyword "foo baz") "bar"} json/parse-stream "{\"foo baz\":\"bar\"}\n"
+      {(keyword "foo baz") "bar"} json/parse-stream-strict "{\"foo baz\":\"bar\"}\n"))
+
+  (testing "generate-stream"
+    (let [sw (StringWriter.)
+          bw (BufferedWriter. sw)]
+      (json/generate-stream {"foo" "bar"} bw)
+      (is (= "{\"foo\":\"bar\"}" (.toString sw))))))
 
 (deftest serial-writing
   (is (= "[\"foo\",\"bar\"]"
@@ -242,6 +251,22 @@
     (is (= (type Double/NaN)
            (type (:foo (json/decode "{\"foo\":NaN}" true)))))))
 
+(deftest t-bindable-factories-quoteless
+  (binding [fact/*json-factory* (fact/make-json-factory
+                                  {:quote-field-names false})]
+    (is (= "{a:1}" (json/encode {:a 1})))))
+
+(deftest t-bindable-factories-strict-duplicate-detection
+  (binding [fact/*json-factory* (fact/make-json-factory
+                                 {:strict-duplicate-detection true})]
+    (is (thrown? JsonParseException
+                 (json/decode "{\"a\": 1, \"b\": 2, \"a\": 3}"))))
+
+  (binding [fact/*json-factory* (fact/make-json-factory
+                                 {:strict-duplicate-detection false})]
+    (is (= {"a" 3 "b" 2}
+           (json/decode "{\"a\": 1, \"b\": 2, \"a\": 3}")))))
+
 (deftest t-persistent-queue
   (let [q (conj (clojure.lang.PersistentQueue/EMPTY) 1 2 3)]
     (is (= q (json/decode (json/encode q))))))
@@ -299,6 +324,20 @@
       (println expected))
     (is (= expected pretty-str))))
 
+(deftest t-custom-pretty-print-with-noident-objects
+  (let [test-obj  [{:foo 1 :bar 2} {:foo 3 :bar 4}]
+        test-opts {:pretty {:indent-objects? false}}
+        expected (str "[ { \"foo\" : 1, \"bar\" : 2 }, "
+                      "{ \"foo\" : 3, \"bar\" : 4 } ]")
+        pretty-str (json/encode test-obj test-opts)]
+    ; just to be easy on the eyes in case of error
+    (when-not (= expected pretty-str)
+      (println "; pretty print with options - actual")
+      (println pretty-str)
+      (println "; pretty print with options - expected")
+      (println expected))
+    (is (= expected pretty-str))))
+
 (deftest t-unicode-escaping
   (is (= "{\"foo\":\"It costs \\u00A3100\"}"
          (json/encode {:foo "It costs £100"} {:escape-non-ascii true}))))
@@ -396,3 +435,18 @@
 
 (deftest t-non-const-bools
   (is (= {:a 1} (json/decode "{\"a\": 1}" (Boolean. true)))))
+
+(deftest t-invalid-json
+  (let [invalid-json-message "Invalid JSON, expected exactly one parseable object but multiple objects were found"]
+    (are [x y] (= x (try
+                      y
+                      (catch Exception e
+                        (.getMessage e))))
+      invalid-json-message (json-exact/decode "{\"foo\": 1}asdf")
+      invalid-json-message (json-exact/decode "{\"foo\": 123}null")
+      invalid-json-message (json-exact/decode  "\"hello\" : 123}")
+      {"foo" 1} (json/decode "{\"foo\": 1}")
+      invalid-json-message (json-exact/decode-strict "{\"foo\": 1}asdf")
+      invalid-json-message (json-exact/decode-strict "{\"foo\": 123}null")
+      invalid-json-message (json-exact/decode-strict  "\"hello\" : 123}")
+      {"foo" 1} (json/decode-strict "{\"foo\": 1}"))))


=====================================
test/cheshire/test/custom.clj
=====================================
@@ -215,6 +215,9 @@
   (is (= {"foo" "bar"} (json/decode "{\"foo\": \"bar\"}" false)))
   (is (= {:foo "bar"} (json/decode "{\"foo\": \"bar\"}" true))))
 
+(deftest t-json-reader-tag
+  (is (= "{\"FOO\":\"bar\"}" #cheshire/json {:FOO "bar"} )))
+
 ;; Begin custom-only tests
 
 (deftest test-add-remove-encoder



View it on GitLab: https://salsa.debian.org/clojure-team/cheshire-clojure/-/commit/d2a87864aa4cef0883ba89d4a2978e0c7409f294

-- 
View it on GitLab: https://salsa.debian.org/clojure-team/cheshire-clojure/-/commit/d2a87864aa4cef0883ba89d4a2978e0c7409f294
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20230205/26ff9927/attachment.htm>


More information about the pkg-java-commits mailing list