From d7b0325a0519ac344fb9da6cfb50bc4077aaec02 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Wed, 19 May 2021 13:04:15 -0500 Subject: [PATCH 01/57] pull dec to top of read-quoted-string --- src/main/clojure/clojure/data/json.clj | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index 747a1ab..e99916e 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/src/main/clojure/clojure/data/json.clj @@ -95,7 +95,8 @@ ;; Expects to be called with the head of the stream AFTER the ;; opening quotation mark. (let [buffer ^chars (char-array 64) - read (.read stream buffer 0 64)] + read (.read stream buffer 0 64) + end-index (unchecked-dec-int read)] (when (neg? read) (throw (EOFException. "JSON error (end-of-file inside string)"))) (loop [i (int 0)] @@ -109,7 +110,7 @@ len (unchecked-subtract-int read off)] (.unread stream buffer off len) (slow-read-string stream (String. buffer 0 i))) - (if (= i (dec read)) + (if (= i end-index) (do (.unread stream c) (slow-read-string stream (String. buffer 0 i))) (recur (unchecked-inc-int i)))))))) From 9489be1084114146050af6c33077edda94bda044 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Wed, 19 May 2021 13:06:00 -0500 Subject: [PATCH 02/57] update changelog for DJSON-51 --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index e8eaf5e..764af73 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,8 @@ Developer Information Change Log ---------------------------------------- +* next + * Fix [DJSON-51]: Fix possible read of x00's in quoted strings on partial stream read * Release [2.3.0] on 2021-May-14 * Fix [DJSON-48]: Make array parsing match spec * Fix [DJSON-18]: Make pprint-json much faster @@ -235,6 +237,7 @@ Change Log * Initial release. * Source-compatible with clojure.contrib.json, except for the name change. +[DJSON-51]: https://clojure.atlassian.net/browse/DJSON-51 [DJSON-48]: https://clojure.atlassian.net/browse/DJSON-48 [DJSON-47]: https://clojure.atlassian.net/browse/DJSON-47 [DJSON-45]: https://clojure.atlassian.net/browse/DJSON-45 From ab4c5e240a414218a41540e33e53561f241e1ccb Mon Sep 17 00:00:00 2001 From: "Hudson @ build.clojure.org" Date: Wed, 19 May 2021 13:12:32 -0500 Subject: [PATCH 03/57] [maven-release-plugin] prepare release v2.3.1 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6fcfde4..8b7cdc5 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 data.json - 2.3.1-SNAPSHOT + 2.3.1 data.json Generating/parsing JSON from/to Clojure data structures https://github.com/clojure/data.json @@ -26,7 +26,7 @@ scm:git:git@github.com:clojure/data.json scm:git:git@github.com:clojure/data.json git@github.com:clojure/data.json.git - HEAD + v2.3.1 From b092ff5719e499a0aca485caceee5241b524a9dc Mon Sep 17 00:00:00 2001 From: "Hudson @ build.clojure.org" Date: Wed, 19 May 2021 13:12:32 -0500 Subject: [PATCH 04/57] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 8b7cdc5..32d007c 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 data.json - 2.3.1 + 2.3.2-SNAPSHOT data.json Generating/parsing JSON from/to Clojure data structures https://github.com/clojure/data.json @@ -26,7 +26,7 @@ scm:git:git@github.com:clojure/data.json scm:git:git@github.com:clojure/data.json git@github.com:clojure/data.json.git - v2.3.1 + HEAD From 72897e0adbdc6cc8fe7ef30a089452048ccb6f80 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Wed, 19 May 2021 13:31:09 -0500 Subject: [PATCH 05/57] update for release --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 764af73..2754257 100644 --- a/README.md +++ b/README.md @@ -13,23 +13,23 @@ Releases and Dependency Information This project follows the version scheme MAJOR.MINOR.PATCH where each component provides some relative indication of the size of the change, but does not follow semantic versioning. In general, all changes endeavor to be non-breaking (by moving to new names rather than by breaking existing names). -Latest stable release is [2.3.0] +Latest stable release is [2.3.1] [CLI/`deps.edn`](https://clojure.org/reference/deps_and_cli) dependency information: ```clojure -org.clojure/data.json {:mvn/version "2.3.0"} +org.clojure/data.json {:mvn/version "2.3.1"} ``` [Leiningen] dependency information: - [org.clojure/data.json "2.3.0"] + [org.clojure/data.json "2.3.1"] [Maven] dependency information: org.clojure data.json - 2.3.0 + 2.3.1 [Leiningen]: https://leiningen.org/ @@ -153,7 +153,7 @@ Developer Information Change Log ---------------------------------------- -* next +* Release [2.3.1] on 2021-May-19 * Fix [DJSON-51]: Fix possible read of x00's in quoted strings on partial stream read * Release [2.3.0] on 2021-May-14 * Fix [DJSON-48]: Make array parsing match spec @@ -266,6 +266,7 @@ Change Log [DJSON-7]: https://clojure.atlassian.net/browse/DJSON-7 [DJSON-1]: https://clojure.atlassian.net/browse/DJSON-1 +[2.3.1]: https://github.com/clojure/data.json/tree/data.json-2.3.1 [2.3.0]: https://github.com/clojure/data.json/tree/data.json-2.3.0 [2.2.3]: https://github.com/clojure/data.json/tree/data.json-2.2.3 [2.2.2]: https://github.com/clojure/data.json/tree/data.json-2.2.2 From b91726cc5f6411a15f0b4ab4b5e7053d78897d0f Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Wed, 19 May 2021 14:49:13 -0500 Subject: [PATCH 06/57] add ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 29c10dc..d6672d7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ target .idea/ *.iml .lein* +.nrepl* From 9b511c9cb6817f1ef139c10b282128b585108d4e Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sat, 10 Jul 2021 19:43:13 +0200 Subject: [PATCH 07/57] DJSON-52: clean up workaround for Clojure < 1.2.x Signed-off-by: Alex Miller --- src/main/clojure/clojure/data/json.clj | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index e99916e..a74810a 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/src/main/clojure/clojure/data/json.clj @@ -621,12 +621,7 @@ (extend java.time.Instant JSONWriter {:-write write-instant}) (extend java.util.Date JSONWriter {:-write write-date}) (extend java.sql.Date JSONWriter {:-write write-sql-date}) -;; Attempt to support Clojure 1.2.x: -(when-let [class (try (.. Thread currentThread getContextClassLoader - (loadClass "clojure.lang.BigInt")) - (catch ClassNotFoundException _ false))] - (extend class JSONWriter {:-write write-bignum})) - +(extend clojure.lang.BigInt JSONWriter {:-write write-bignum}) ;; Symbols, Keywords, and Strings (extend clojure.lang.Named JSONWriter {:-write write-named}) From 12344bbb98ae3070607268f210f393a64f5051dd Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Mon, 12 Jul 2021 15:25:11 -0500 Subject: [PATCH 08/57] move 0.1.x deprecated api from separate file into main ns --- src/main/clojure/clojure/data/json.clj | 72 ++++++++++++++++-- .../clojure/clojure/data/json_compat_0_1.clj | 73 ------------------- 2 files changed, 66 insertions(+), 79 deletions(-) delete mode 100644 src/main/clojure/clojure/data/json_compat_0_1.clj diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index a74810a..62320f5 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/src/main/clojure/clojure/data/json.clj @@ -741,9 +741,69 @@ (pprint/with-pprint-dispatch #(pprint-dispatch % opts) (pprint/pprint x)))) -(load "json_compat_0_1") - -;; Local Variables: -;; mode: clojure -;; eval: (define-clojure-indent (codepoint-case (quote defun))) -;; End: +;; DEPRECATED APIs from 0.1.x + +(defn read-json + "DEPRECATED; replaced by read-str. + + Reads one JSON value from input String or Reader. If keywordize? is + true (default), object keys will be converted to keywords. If + eof-error? is true (default), empty input will throw an + EOFException; if false EOF will return eof-value." + ([input] + (read-json input true true nil)) + ([input keywordize?] + (read-json input keywordize? true nil)) + ([input keywordize? eof-error? eof-value] + (let [key-fn (if keywordize? keyword identity)] + (condp instance? input + String + (read-str input + :key-fn key-fn + :eof-error? eof-error? + :eof-value eof-value) + java.io.Reader + (read input + :key-fn key-fn + :eof-error? eof-error? + :eof-value eof-value))))) + +(defn write-json + "DEPRECATED; replaced by 'write'. + + Print object to PrintWriter out as JSON" + [x out escape-unicode?] + (write x out :escape-unicode escape-unicode?)) + +(defn json-str + "DEPRECATED; replaced by 'write-str'. + + Converts x to a JSON-formatted string. + + Valid options are: + :escape-unicode false + to turn of \\uXXXX escapes of Unicode characters." + [x & options] + (apply write-str x options)) + +(defn print-json + "DEPRECATED; replaced by 'write' to *out*. + + Write JSON-formatted output to *out*. + + Valid options are: + :escape-unicode false + to turn off \\uXXXX escapes of Unicode characters." + [x & options] + (apply write x *out* options)) + +(defn pprint-json + "DEPRECATED; replaced by 'pprint'. + + Pretty-prints JSON representation of x to *out*. + + Valid options are: + :escape-unicode false + to turn off \\uXXXX escapes of Unicode characters." + [x & options] + (apply pprint x options)) \ No newline at end of file diff --git a/src/main/clojure/clojure/data/json_compat_0_1.clj b/src/main/clojure/clojure/data/json_compat_0_1.clj deleted file mode 100644 index 1455623..0000000 --- a/src/main/clojure/clojure/data/json_compat_0_1.clj +++ /dev/null @@ -1,73 +0,0 @@ -;; Copyright (c) Stuart Sierra, 2012. All rights reserved. The use and -;; distribution terms for this software are covered by the Eclipse -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) -;; By using this software in any fashion, you are agreeing to be bound -;; by the terms of this license. You must not remove this notice, or -;; any other, from this software. - -(in-ns 'clojure.data.json) - -(defn read-json - "DEPRECATED; replaced by read-str. - - Reads one JSON value from input String or Reader. If keywordize? is - true (default), object keys will be converted to keywords. If - eof-error? is true (default), empty input will throw an - EOFException; if false EOF will return eof-value." - ([input] - (read-json input true true nil)) - ([input keywordize?] - (read-json input keywordize? true nil)) - ([input keywordize? eof-error? eof-value] - (let [key-fn (if keywordize? keyword identity)] - (condp instance? input - String - (read-str input - :key-fn key-fn - :eof-error? eof-error? - :eof-value eof-value) - java.io.Reader - (read input - :key-fn key-fn - :eof-error? eof-error? - :eof-value eof-value))))) - -(defn write-json - "DEPRECATED; replaced by 'write'. - - Print object to PrintWriter out as JSON" - [x out escape-unicode?] - (write x out :escape-unicode escape-unicode?)) - -(defn json-str - "DEPRECATED; replaced by 'write-str'. - - Converts x to a JSON-formatted string. - - Valid options are: - :escape-unicode false - to turn of \\uXXXX escapes of Unicode characters." - [x & options] - (apply write-str x options)) - -(defn print-json - "DEPRECATED; replaced by 'write' to *out*. - - Write JSON-formatted output to *out*. - - Valid options are: - :escape-unicode false - to turn off \\uXXXX escapes of Unicode characters." - [x & options] - (apply write x *out* options)) - -(defn pprint-json - "DEPRECATED; replaced by 'pprint'. - - Pretty-prints JSON representation of x to *out*. - - Valid options are: - :escape-unicode false - to turn off \\uXXXX escapes of Unicode characters." - [x & options] - (apply pprint x options)) From a94935392416c244f982d81dea67099af4402e93 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Mon, 12 Jul 2021 15:26:45 -0500 Subject: [PATCH 09/57] update changelog --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 2754257..b0d568d 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,9 @@ Developer Information Change Log ---------------------------------------- +* next + * Fix [DJSON-52]: Remove Classloader workaround to support Clojure 1.2.x and below + * Fix [DJSON-53]: Move deprecated API functions from compat ns into main ns * Release [2.3.1] on 2021-May-19 * Fix [DJSON-51]: Fix possible read of x00's in quoted strings on partial stream read * Release [2.3.0] on 2021-May-14 From 43c122e91c5c5e46dc58dc7e8fcbb64bb9f88a14 Mon Sep 17 00:00:00 2001 From: "Hudson @ build.clojure.org" Date: Mon, 12 Jul 2021 15:29:30 -0500 Subject: [PATCH 10/57] [maven-release-plugin] prepare release v2.4.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 32d007c..9738307 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 data.json - 2.3.2-SNAPSHOT + 2.4.0 data.json Generating/parsing JSON from/to Clojure data structures https://github.com/clojure/data.json @@ -26,7 +26,7 @@ scm:git:git@github.com:clojure/data.json scm:git:git@github.com:clojure/data.json git@github.com:clojure/data.json.git - HEAD + v2.4.0 From e1e06fcc71bf862c149aaa733fe10a8e6e6b1d96 Mon Sep 17 00:00:00 2001 From: "Hudson @ build.clojure.org" Date: Mon, 12 Jul 2021 15:29:30 -0500 Subject: [PATCH 11/57] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 9738307..3cdaccf 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 data.json - 2.4.0 + 2.4.1-SNAPSHOT data.json Generating/parsing JSON from/to Clojure data structures https://github.com/clojure/data.json @@ -26,7 +26,7 @@ scm:git:git@github.com:clojure/data.json scm:git:git@github.com:clojure/data.json git@github.com:clojure/data.json.git - v2.4.0 + HEAD From 9f1c9ccf3fd3e5a39cfb7289d3d456e842ddf442 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Mon, 12 Jul 2021 15:36:40 -0500 Subject: [PATCH 12/57] update for release --- README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b0d568d..0c66ede 100644 --- a/README.md +++ b/README.md @@ -13,23 +13,23 @@ Releases and Dependency Information This project follows the version scheme MAJOR.MINOR.PATCH where each component provides some relative indication of the size of the change, but does not follow semantic versioning. In general, all changes endeavor to be non-breaking (by moving to new names rather than by breaking existing names). -Latest stable release is [2.3.1] +Latest stable release is [2.4.0] [CLI/`deps.edn`](https://clojure.org/reference/deps_and_cli) dependency information: ```clojure -org.clojure/data.json {:mvn/version "2.3.1"} +org.clojure/data.json {:mvn/version "2.4.0"} ``` [Leiningen] dependency information: - [org.clojure/data.json "2.3.1"] + [org.clojure/data.json "2.4.0"] [Maven] dependency information: org.clojure data.json - 2.3.1 + 2.4.0 [Leiningen]: https://leiningen.org/ @@ -153,7 +153,7 @@ Developer Information Change Log ---------------------------------------- -* next +* Release [2.4.0] on 2021-Jul-12 * Fix [DJSON-52]: Remove Classloader workaround to support Clojure 1.2.x and below * Fix [DJSON-53]: Move deprecated API functions from compat ns into main ns * Release [2.3.1] on 2021-May-19 @@ -240,6 +240,8 @@ Change Log * Initial release. * Source-compatible with clojure.contrib.json, except for the name change. +[DJSON-53]: https://clojure.atlassian.net/browse/DJSON-53 +[DJSON-52]: https://clojure.atlassian.net/browse/DJSON-52 [DJSON-51]: https://clojure.atlassian.net/browse/DJSON-51 [DJSON-48]: https://clojure.atlassian.net/browse/DJSON-48 [DJSON-47]: https://clojure.atlassian.net/browse/DJSON-47 @@ -269,6 +271,7 @@ Change Log [DJSON-7]: https://clojure.atlassian.net/browse/DJSON-7 [DJSON-1]: https://clojure.atlassian.net/browse/DJSON-1 +[2.4.0]: https://github.com/clojure/data.json/tree/data.json-2.4.0 [2.3.1]: https://github.com/clojure/data.json/tree/data.json-2.3.1 [2.3.0]: https://github.com/clojure/data.json/tree/data.json-2.3.0 [2.2.3]: https://github.com/clojure/data.json/tree/data.json-2.2.3 From 2567660682c126adc47da7e1fd17e37201f2d83e Mon Sep 17 00:00:00 2001 From: John Shaffer Date: Sat, 26 Feb 2022 13:20:42 -0600 Subject: [PATCH 13/57] Handle end-of-file in object and array readers --- src/main/clojure/clojure/data/json.clj | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index 62320f5..ac911d6 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/src/main/clojure/clojure/data/json.clj @@ -278,6 +278,7 @@ (codepoint-case c \] [] \, (throw (invalid-array-exception)) + -1 (throw (Exception. "JSON error (end-of-file inside array)")) (do (.unread stream c) (read-array* stream options))))) @@ -288,8 +289,9 @@ (if (= (codepoint \:) (int (next-token stream))) key (throw (Exception. "JSON error (missing `:` in object)")))) - (if (= c (codepoint \})) - nil + (codepoint-case c + \} nil + -1 (throw (Exception. "JSON error (end-of-file inside object)")) (throw (Exception. (str "JSON error (non-string key in object), found `" (char c) "`, expected `\"`"))))))) (defn- read-object [^PushbackReader stream options] @@ -310,6 +312,7 @@ (codepoint-case (int (next-token stream)) \, (recur r) \} (persistent! r) + -1 (throw (Exception. "JSON error (end-of-file inside object)")) (throw (Exception. "JSON error (missing entry in object)")))) (let [r (persistent! result)] (if (empty? r) @@ -806,4 +809,4 @@ :escape-unicode false to turn off \\uXXXX escapes of Unicode characters." [x & options] - (apply pprint x options)) \ No newline at end of file + (apply pprint x options)) From 0b491b25e61d108951c64d33d28a90080758a271 Mon Sep 17 00:00:00 2001 From: Fogus Date: Fri, 2 Sep 2022 16:16:42 -0400 Subject: [PATCH 14/57] Revert "Handle end-of-file in object and array readers" This was meant for a branch. This reverts commit 2567660682c126adc47da7e1fd17e37201f2d83e. --- src/main/clojure/clojure/data/json.clj | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index ac911d6..62320f5 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/src/main/clojure/clojure/data/json.clj @@ -278,7 +278,6 @@ (codepoint-case c \] [] \, (throw (invalid-array-exception)) - -1 (throw (Exception. "JSON error (end-of-file inside array)")) (do (.unread stream c) (read-array* stream options))))) @@ -289,9 +288,8 @@ (if (= (codepoint \:) (int (next-token stream))) key (throw (Exception. "JSON error (missing `:` in object)")))) - (codepoint-case c - \} nil - -1 (throw (Exception. "JSON error (end-of-file inside object)")) + (if (= c (codepoint \})) + nil (throw (Exception. (str "JSON error (non-string key in object), found `" (char c) "`, expected `\"`"))))))) (defn- read-object [^PushbackReader stream options] @@ -312,7 +310,6 @@ (codepoint-case (int (next-token stream)) \, (recur r) \} (persistent! r) - -1 (throw (Exception. "JSON error (end-of-file inside object)")) (throw (Exception. "JSON error (missing entry in object)")))) (let [r (persistent! result)] (if (empty? r) @@ -809,4 +806,4 @@ :escape-unicode false to turn off \\uXXXX escapes of Unicode characters." [x & options] - (apply pprint x options)) + (apply pprint x options)) \ No newline at end of file From 08fddee609a136abc5ff8641ff3554ad6bf4ab57 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Fri, 26 May 2023 15:16:28 -0500 Subject: [PATCH 15/57] add actions --- .github/workflows/release.yml | 19 +++++++++++++++++++ .github/workflows/snapshot.yml | 8 ++++++++ .github/workflows/test.yml | 7 +++++++ README.md | 5 +---- 4 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/snapshot.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e2718bd --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,19 @@ +name: Release on demand + +on: + workflow_dispatch: + inputs: + releaseVersion: + description: "Version to release" + required: true + snapshotVersion: + description: "Snapshot version after release" + required: true + +jobs: + call-release: + uses: clojure/build.ci/.github/workflows/release.yml@master + with: + releaseVersion: ${{ github.event.inputs.releaseVersion }} + snapshotVersion: ${{ github.event.inputs.snapshotVersion }} + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml new file mode 100644 index 0000000..2472957 --- /dev/null +++ b/.github/workflows/snapshot.yml @@ -0,0 +1,8 @@ +name: Snapshot on demand + +on: [workflow_dispatch] + +jobs: + call-snapshot: + uses: clojure/build.ci/.github/workflows/snapshot.yml@master + secrets: inherit diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..1fa127c --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,7 @@ +name: Test + +on: [push] + +jobs: + call-test: + uses: clojure/build.ci/.github/workflows/test.yml@master diff --git a/README.md b/README.md index 0c66ede..38bad14 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,7 @@ org.clojure/data.json {:mvn/version "2.4.0"} Other versions: * [All Released Versions](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.clojure%22%20AND%20a%3A%22data.json%22) - * [Development Snapshots](https://oss.sonatype.org/index.html#nexus-search;gav~org.clojure~data.json~~~) - * [Development Snapshot Repositories](https://clojure.org/releases/downloads#_using_clojure_snapshot_releases) @@ -145,8 +143,7 @@ Developer Information * [GitHub project](https://github.com/clojure/data.json) * [How to contribute](https://clojure.org/community/contributing) * [Bug Tracker](https://clojure.atlassian.net/browse/DJSON) -* [Continuous Integration](https://build.clojure.org/job/data.json/) -* [Compatibility Test Matrix](https://build.clojure.org/job/data.json-test-matrix/) +* [Continuous Integration](https://github.com/clojure/data.json/actions/workflows/test.yml) From 9ff5b5012fff47c66687be4680b120b9fd3ae940 Mon Sep 17 00:00:00 2001 From: JarrodCTaylor Date: Wed, 9 Aug 2023 18:23:35 -0500 Subject: [PATCH 16/57] Added github action to build api docs --- .github/workflows/doc-build.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .github/workflows/doc-build.yml diff --git a/.github/workflows/doc-build.yml b/.github/workflows/doc-build.yml new file mode 100644 index 0000000..e379e5d --- /dev/null +++ b/.github/workflows/doc-build.yml @@ -0,0 +1,10 @@ +name: Build API Docs + +on: + workflow_dispatch: + +jobs: + call-doc-build-workflow: + uses: clojure/build.ci/.github/workflows/doc-build.yml@master + with: + project: clojure/data.json From fe77d05f5a035c46ba40593441234827d2d1ee11 Mon Sep 17 00:00:00 2001 From: JarrodCTaylor Date: Wed, 30 Aug 2023 22:20:25 -0500 Subject: [PATCH 17/57] Fix EPL license link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 38bad14..2f36395 100644 --- a/README.md +++ b/README.md @@ -303,7 +303,7 @@ Copyright and License Copyright (c) Stuart Sierra, Rich Hickey, and contriburos 2012-2020. All rights reserved. The use and distribution terms for this software are covered by the Eclipse Public -License 1.0 (https://opensource.org/licenses/eclipse-1.0.php) which can +License 1.0 (https://opensource.org/license/epl-1-0/) witch can be found in the file epl-v10.html at the root of this distribution. By using this software in any fashion, you are agreeing to be bound by the terms of this license. You must not remove this notice, or any From 91f5660d30eefcdda7ca0c4a0232b6d7e75e2d8b Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Fri, 1 Dec 2023 13:32:08 -0600 Subject: [PATCH 18/57] Add :indent to `write` docstring per DJSON-18 --- README.md | 2 ++ src/main/clojure/clojure/data/json.clj | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2f36395..2c22eaa 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,8 @@ Developer Information Change Log ---------------------------------------- +* Next + * Add `:indent` to docstring for option added in [DJSON-18] * Release [2.4.0] on 2021-Jul-12 * Fix [DJSON-52]: Remove Classloader workaround to support Clojure 1.2.x and below * Fix [DJSON-53]: Move deprecated API functions from compat ns into main ns diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index 62320f5..0744258 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/src/main/clojure/clojure/data/json.clj @@ -642,7 +642,8 @@ :key-fn default-write-key-fn :value-fn default-value-fn :indent false - :indent-depth 0}) + :indent-depth 0 ;; internal, to track nesting depth + }) (defn write "Write JSON-formatted output to a java.io.Writer. Options are key-value pairs, valid options are: @@ -696,7 +697,11 @@ the return value is a map, it will be processed recursively, calling value-fn again on its key-value pairs. If value-fn returns itself, the key-value pair will be omitted from the - output. This option does not apply to non-map collections." + output. This option does not apply to non-map collections. + + :indent boolean + + If true, indent json while writing (default = false)." [x ^Writer writer & {:as options}] (-write x writer (merge default-write-options options))) From d51234eb52044326b27baf6b6cab6389568cc8cf Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Sat, 2 Dec 2023 11:06:12 -0600 Subject: [PATCH 19/57] update docstring for pprint to omit :indent as an option --- src/main/clojure/clojure/data/json.clj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index 0744258..219d480 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/src/main/clojure/clojure/data/json.clj @@ -739,8 +739,8 @@ :else (pprint-generic x options))) (defn pprint - "Pretty-prints JSON representation of x to *out*. Options are the - same as for write except :value-fn, which is not supported." + "Pretty-prints JSON representation of x to *out*. Options are the same + as for write except :value-fn and :indent, which are not supported." [x & {:as options}] (let [opts (merge default-write-options options)] (pprint/with-pprint-dispatch #(pprint-dispatch % opts) @@ -811,4 +811,4 @@ :escape-unicode false to turn off \\uXXXX escapes of Unicode characters." [x & options] - (apply pprint x options)) \ No newline at end of file + (apply pprint x options)) From cb79051f7ce98cc8ecf88a67707c5eb6b452552e Mon Sep 17 00:00:00 2001 From: Erik Assum Date: Wed, 6 Dec 2023 00:03:28 +0100 Subject: [PATCH 20/57] DJSON-61 Create a faster write-string Signed-off-by: Alex Miller --- src/main/clojure/clojure/data/json.clj | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index 0744258..9588cf3 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/src/main/clojure/clojure/data/json.clj @@ -454,9 +454,8 @@ (aset shorts i (short 0))))) shorts)) -(defn- write-string [^CharSequence s ^Appendable out options] +(defn- slow-write-string [^CharSequence s ^Appendable out options] (let [decoder codepoint-decoder] - (.append out \") (dotimes [i (.length s)] (let [cp (int (.charAt s i))] (if (< cp 128) @@ -476,7 +475,22 @@ (.append out (char cp))) (if (get options :escape-unicode) (->hex-string out cp) ; Hexadecimal-escaped - (.append out (char cp))))))) + (.append out (char cp))))))))) + +(defn- write-string [^CharSequence s ^Appendable out options] + (let [decoder codepoint-decoder + l (.length s)] + (.append out \") + (loop [i 0] + (if (= i l) + (.append out s) + (let [cp (int (.charAt s i))] + (if (and (< cp 128) + (zero? (aget decoder cp))) + (recur (unchecked-inc i)) + (do + (.append out s 0 i) + (slow-write-string (.subSequence s i l) out options)))))) (.append out \"))) (defn- write-indent [^Appendable out options] From ed3429862d2997b8049bbe5ba49b922fb7665bff Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Tue, 19 Dec 2023 17:07:48 -0600 Subject: [PATCH 21/57] update changelog --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c22eaa..ce736cc 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,7 @@ Change Log ---------------------------------------- * Next + * Perf [DJSON-61]: Faster string writing when string is "simple" * Add `:indent` to docstring for option added in [DJSON-18] * Release [2.4.0] on 2021-Jul-12 * Fix [DJSON-52]: Remove Classloader workaround to support Clojure 1.2.x and below @@ -239,6 +240,7 @@ Change Log * Initial release. * Source-compatible with clojure.contrib.json, except for the name change. +[DJSON-61]: https://clojure.atlassian.net/browse/DJSON-61 [DJSON-53]: https://clojure.atlassian.net/browse/DJSON-53 [DJSON-52]: https://clojure.atlassian.net/browse/DJSON-52 [DJSON-51]: https://clojure.atlassian.net/browse/DJSON-51 @@ -302,7 +304,7 @@ Change Log Copyright and License ---------------------------------------- -Copyright (c) Stuart Sierra, Rich Hickey, and contriburos 2012-2020. +Copyright (c) Stuart Sierra, Rich Hickey, and contributors. All rights reserved. The use and distribution terms for this software are covered by the Eclipse Public License 1.0 (https://opensource.org/license/epl-1-0/) witch can From 52cb46cf14645e554a1fe6916dc69b79ec0071bd Mon Sep 17 00:00:00 2001 From: Erik Assum Date: Wed, 20 Dec 2023 09:54:59 -0600 Subject: [PATCH 22/57] DJSON-54 Add custom fallback fn for writing unknown types Signed-off-by: Alex Miller --- src/main/clojure/clojure/data/json.clj | 13 ++++++++++++- src/test/clojure/clojure/data/json_test.clj | 10 ++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index 51f581f..3127d16 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/src/main/clojure/clojure/data/json.clj @@ -610,7 +610,7 @@ (defn- write-generic [x out options] (if (.isArray (class x)) (-write (seq x) out options) - (throw (Exception. (str "Don't know how to write JSON of " (class x)))))) + ((:default-write-fn options) x out options))) (defn- write-ratio [x out options] (-write (double x) out options)) @@ -648,6 +648,9 @@ ;; Maybe a Java array, otherwise fail (extend java.lang.Object JSONWriter {:-write write-generic}) +(defn- default-write-fn [x out options] + (throw (Exception. (str "Don't know how to write JSON of " (class x))))) + (def default-write-options {:escape-unicode true :escape-js-separators true :escape-slash true @@ -655,6 +658,7 @@ :date-formatter java.time.format.DateTimeFormatter/ISO_INSTANT :key-fn default-write-key-fn :value-fn default-value-fn + :default-write-fn default-write-fn :indent false :indent-depth 0 ;; internal, to track nesting depth }) @@ -713,6 +717,13 @@ returns itself, the key-value pair will be omitted from the output. This option does not apply to non-map collections. + :default-write-fn function + + Function to handle types which are unknown to data.json. Defaults + to a function which throws an exception. Expects to be called with + three args, the value to be serialized, the output stream, and the + options map. + :indent boolean If true, indent json while writing (default = false)." diff --git a/src/test/clojure/clojure/data/json_test.clj b/src/test/clojure/clojure/data/json_test.clj index 70ea218..899510a 100644 --- a/src/test/clojure/clojure/data/json_test.clj +++ b/src/test/clojure/clojure/data/json_test.clj @@ -423,3 +423,13 @@ (dotimes [_ 1000] (assert (= (json/read-str pass1-string) (json/read-str (json/write-str (json/read-str pass1-string))))))))) + +(defn djson-54-default-write-fn [x out options] + (#'json/write-string (str x) out options)) + +(deftest DJSON-54-test + (is (thrown? Exception (json/write-str {:foo (java.net.URI. "http://clojure.org")}))) + (try (json/write-str {:foo (java.net.URI. "http://clojure.org")}) + (catch Exception e + (is (= "Don't know how to write JSON of class java.net.URI" (.getMessage e))))) + (is (= "{\"foo\":\"http:\\/\\/clojure.org\"}" (json/write-str {:foo (java.net.URI. "http://clojure.org")} :default-write-fn djson-54-default-write-fn)))) From 3fa0d0a44fd2d8fecb3370ebf8f1824f2c17af23 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Wed, 20 Dec 2023 09:58:34 -0600 Subject: [PATCH 23/57] update changelog --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ce736cc..bc8b044 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,7 @@ Change Log * Next * Perf [DJSON-61]: Faster string writing when string is "simple" + * Add [DJSON-54]: Add custom fallback fn for writing unknown types * Add `:indent` to docstring for option added in [DJSON-18] * Release [2.4.0] on 2021-Jul-12 * Fix [DJSON-52]: Remove Classloader workaround to support Clojure 1.2.x and below @@ -241,6 +242,7 @@ Change Log * Source-compatible with clojure.contrib.json, except for the name change. [DJSON-61]: https://clojure.atlassian.net/browse/DJSON-61 +[DJSON-54]: https://clojure.atlassian.net/browse/DJSON-54 [DJSON-53]: https://clojure.atlassian.net/browse/DJSON-53 [DJSON-52]: https://clojure.atlassian.net/browse/DJSON-52 [DJSON-51]: https://clojure.atlassian.net/browse/DJSON-51 From c8e41562b7c064f0e3a592ec3e6bd5f93b7e6d14 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Wed, 20 Dec 2023 12:38:40 -0600 Subject: [PATCH 24/57] DJSON-50 Allow user to pass PushbackReader to read for repeated read on the same reader Signed-off-by: Alex Miller --- src/main/clojure/clojure/data/json.clj | 15 +++++++++++---- src/test/clojure/clojure/data/json_test.clj | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index 3127d16..81ff502 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/src/main/clojure/clojure/data/json.clj @@ -367,8 +367,12 @@ :key-fn nil :value-fn nil}) (defn read - "Reads a single item of JSON data from a java.io.Reader. Options are - key-value pairs, valid options are: + "Reads a single item of JSON data from a java.io.Reader. + + If you wish to repeatedly read items from the same reader, you must + supply a PushbackReader and reuse it on subsequent calls. + + Options are key-value pairs, valid options are: :eof-error? boolean @@ -403,10 +407,13 @@ collections." [reader & {:as options}] (let [{:keys [eof-error? eof-value] - :or {eof-error? true}} options] + :or {eof-error? true}} options + pbr (if (instance? PushbackReader reader) + reader + (PushbackReader. reader 64))] (->> options (merge default-read-options) - (-read (PushbackReader. reader 64) eof-error? eof-value)))) + (-read pbr eof-error? eof-value)))) (defn read-str "Reads one JSON value from input String. Options are the same as for diff --git a/src/test/clojure/clojure/data/json_test.clj b/src/test/clojure/clojure/data/json_test.clj index 899510a..6779ad2 100644 --- a/src/test/clojure/clojure/data/json_test.clj +++ b/src/test/clojure/clojure/data/json_test.clj @@ -7,6 +7,20 @@ (let [s (java.io.PushbackReader. (java.io.StringReader. "42"))] (is (= 42 (json/read s))))) +;; DJSON-50 - pass PBR to safely do reapeated read +(deftest read-multiple + (let [st "{\"foo\":\"some string\"}{\"foo\":\"another string\"}" + srdr (java.io.StringReader. st) + pbr (java.io.PushbackReader. srdr 64)] + (is (= {"foo" "some string"} (json/read pbr))) + (is (= {"foo" "another string"} (json/read pbr)))) + + (let [st "{\"foo\":\"some string\"}{\"foo\":\"another long ......................................................... string\"}" + srdr (java.io.StringReader. st) + pbr (java.io.PushbackReader. srdr 64)] + (is (= {"foo" "some string"} (json/read pbr))) + (is (= {"foo" "another long ......................................................... string"} (json/read pbr))))) + (deftest read-from-reader (let [s (java.io.StringReader. "42")] (is (= 42 (json/read s))))) From 9a34b98a6c85c979afda9f13f73cdf66ce628082 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Wed, 20 Dec 2023 12:41:12 -0600 Subject: [PATCH 25/57] update changelog --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bc8b044..24cfcf8 100644 --- a/README.md +++ b/README.md @@ -151,9 +151,10 @@ Change Log ---------------------------------------- * Next - * Perf [DJSON-61]: Faster string writing when string is "simple" + * Fix [DJSON-50]: read can take a PushbackReader for repeated read use case * Add [DJSON-54]: Add custom fallback fn for writing unknown types * Add `:indent` to docstring for option added in [DJSON-18] + * Perf [DJSON-61]: Faster string writing when string is "simple" * Release [2.4.0] on 2021-Jul-12 * Fix [DJSON-52]: Remove Classloader workaround to support Clojure 1.2.x and below * Fix [DJSON-53]: Move deprecated API functions from compat ns into main ns From 721f0f3d4bdf6ef1480dc71fdb6fce0482f32f31 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Wed, 20 Dec 2023 12:42:21 -0600 Subject: [PATCH 26/57] update changelog --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 24cfcf8..a964be1 100644 --- a/README.md +++ b/README.md @@ -247,6 +247,7 @@ Change Log [DJSON-53]: https://clojure.atlassian.net/browse/DJSON-53 [DJSON-52]: https://clojure.atlassian.net/browse/DJSON-52 [DJSON-51]: https://clojure.atlassian.net/browse/DJSON-51 +[DJSON-50]: https://clojure.atlassian.net/browse/DJSON-50 [DJSON-48]: https://clojure.atlassian.net/browse/DJSON-48 [DJSON-47]: https://clojure.atlassian.net/browse/DJSON-47 [DJSON-45]: https://clojure.atlassian.net/browse/DJSON-45 From 564c737eb2d27727be64e8245806b48da03d04f3 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Wed, 20 Dec 2023 13:56:14 -0600 Subject: [PATCH 27/57] changelog updates --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a964be1..d964213 100644 --- a/README.md +++ b/README.md @@ -151,9 +151,9 @@ Change Log ---------------------------------------- * Next - * Fix [DJSON-50]: read can take a PushbackReader for repeated read use case - * Add [DJSON-54]: Add custom fallback fn for writing unknown types - * Add `:indent` to docstring for option added in [DJSON-18] + * Fix [DJSON-50]: `read` can take a PushbackReader for repeated read use case + * Fix `write` docstring to add `:indent` option added in [DJSON-18] + * Add [DJSON-54]: In `write`, add custom fallback fn for writing unknown types * Perf [DJSON-61]: Faster string writing when string is "simple" * Release [2.4.0] on 2021-Jul-12 * Fix [DJSON-52]: Remove Classloader workaround to support Clojure 1.2.x and below From 1da5545201a8de9f857705f8dab90266c7e56183 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Wed, 20 Dec 2023 16:21:27 -0600 Subject: [PATCH 28/57] add type hint --- src/test/clojure/clojure/data/json_test.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/clojure/clojure/data/json_test.clj b/src/test/clojure/clojure/data/json_test.clj index 6779ad2..2602c81 100644 --- a/src/test/clojure/clojure/data/json_test.clj +++ b/src/test/clojure/clojure/data/json_test.clj @@ -136,7 +136,7 @@ :key-fn keyword :value-fn (fn [k v] (if (= :date k) - (java.sql.Date/valueOf v) + (java.sql.Date/valueOf ^String v) v)))))) (deftest omit-values From 71ed0418aae69f575fc8fa9ce82dffec5f2f0aa3 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Wed, 20 Dec 2023 17:13:58 -0600 Subject: [PATCH 29/57] DJSON-46 Add :extra-data-fn to read - if provided and a json value has been read, the strema will be checked for remaining unread data and the function called if found Signed-off-by: Alex Miller --- src/main/clojure/clojure/data/json.clj | 41 +++++++++++++++++++-- src/test/clojure/clojure/data/json_test.clj | 29 +++++++++++++++ 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index 81ff502..7f688ab 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/src/main/clojure/clojure/data/json.clj @@ -363,6 +363,34 @@ (throw (Exception. (str "JSON error (unexpected character): " (char c)))))))) +(defn- -read1 + [^PushbackReader stream eof-error? eof-value options] + (let [val (-read stream eof-error? eof-value options)] + (if-let [extra-data-fn (:extra-data-fn options)] + (if (or eof-error? (not (identical? eof-value val))) + (let [c (.read stream)] + (if (neg? c) + val + (do + (.unread stream c) + (extra-data-fn val stream)))) + val) + val))) + +(defn on-extra-throw + "Pass as :extra-data-fn to `read` or `read-str` to throw if data is found + after the first object." + [val rdr] + (throw (ex-info "Found extra data after json object" {:val val}))) + +(defn on-extra-throw-remaining + "Pass as :extra-data-fn to `read` or `read-str` to throw if data is found + after the first object and return the remaining data in ex-data :remaining." + [val ^java.io.PushbackReader rdr] + (let [remaining (slurp rdr)] + (throw (ex-info (str "Found extra data after json object: " remaining) + {:val val, :remaining remaining})))) + (def default-read-options {:bigdec false :key-fn nil :value-fn nil}) @@ -404,7 +432,14 @@ in the output. If value-fn returns itself, the property will be omitted from the output. The default value-fn returns the value unchanged. This option does not apply to non-map - collections." + collections. + + :extra-data-fn function + + If :extra-data-fn is not nil, then the reader will be checked + for extra data after the read. If found, the extra-data-fn will + be invoked with the read value and the reader. The result of + the extra-data-fn will be returned." [reader & {:as options}] (let [{:keys [eof-error? eof-value] :or {eof-error? true}} options @@ -413,7 +448,7 @@ (PushbackReader. reader 64))] (->> options (merge default-read-options) - (-read pbr eof-error? eof-value)))) + (-read1 pbr eof-error? eof-value)))) (defn read-str "Reads one JSON value from input String. Options are the same as for @@ -423,7 +458,7 @@ :or {eof-error? true}} options] (->> options (merge default-read-options) - (-read (PushbackReader. (StringReader. string) 64) eof-error? eof-value)))) + (-read1 (PushbackReader. (StringReader. string) 64) eof-error? eof-value)))) ;;; JSON WRITER diff --git a/src/test/clojure/clojure/data/json_test.clj b/src/test/clojure/clojure/data/json_test.clj index 2602c81..8eb0354 100644 --- a/src/test/clojure/clojure/data/json_test.clj +++ b/src/test/clojure/clojure/data/json_test.clj @@ -35,6 +35,35 @@ (is (= 123456789012345678901234567890N (json/read-str "123456789012345678901234567890")))) +(deftest lenient-on-extra-data + (is (= [42] (json/read-str "[42],abc"))) + (is (= [42] (json/read (java.io.StringReader. "[42],abc"))))) + +(deftest strict-on-extra-data + ;; on-extra-throw + (is (thrown? clojure.lang.ExceptionInfo + (json/read-str "[42],abc" :extra-data-fn json/on-extra-throw))) + (is (thrown? clojure.lang.ExceptionInfo + (json/read (java.io.StringReader. "[42],abc") :extra-data-fn json/on-extra-throw))) + + ;; on-extra-throw-remaining + (try + (json/read-str "[42],abc" :extra-data-fn json/on-extra-throw-remaining) + (is false "expected exception to be thrown") + (catch clojure.lang.ExceptionInfo e + (is (= ",abc" (:remaining (ex-data e)))))) + (try + (json/read-str "[1], 1]" :extra-data-fn json/on-extra-throw-remaining) + (is false "expected exception to be thrown") + (catch clojure.lang.ExceptionInfo e + (is (= ", 1]" (:remaining (ex-data e)))))) + + ;; check that empty input behavior not modified when :extra-data-fn specified + (is (= :hi (json/read-str "" + :eof-error? false, :eof-value :hi, :extra-data-fn json/on-extra-throw))) + (is (= :hi (json/read (java.io.StringReader. "") + :eof-error? false, :eof-value :hi, :extra-data-fn json/on-extra-throw)))) + (deftest write-bigint (is (= "123456789012345678901234567890" (json/write-str 123456789012345678901234567890N)))) From 03a366d7d35c1ae459ece7ae257a389dbad58068 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Wed, 20 Dec 2023 17:30:21 -0600 Subject: [PATCH 30/57] update changelog --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d964213..2e9135d 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ Change Log * Next * Fix [DJSON-50]: `read` can take a PushbackReader for repeated read use case * Fix `write` docstring to add `:indent` option added in [DJSON-18] + * Add [DJSON-46]: In `read`, add `:extra-data-fn` that can be provided to cause an eof check after value is read * Add [DJSON-54]: In `write`, add custom fallback fn for writing unknown types * Perf [DJSON-61]: Faster string writing when string is "simple" * Release [2.4.0] on 2021-Jul-12 From 235d0435bc13d6701c24993c0d0205ab8f8fe1bc Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Thu, 21 Dec 2023 10:44:25 -0600 Subject: [PATCH 31/57] custom reader wip --- src/main/clojure/clojure/data/json.clj | 171 +++++++++++++++++-------- 1 file changed, 118 insertions(+), 53 deletions(-) diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index 7f688ab..8d67418 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/src/main/clojure/clojure/data/json.clj @@ -15,6 +15,70 @@ (:import (java.io PrintWriter PushbackReader StringWriter Writer StringReader EOFException))) +;; CUSTOM PUSHBACK READER + +(set! *warn-on-reflection* true) + +(definterface InternalPBR + (^int readChar []) + (^long readChars [^chars buffer ^long start ^long bufflen]) + (^void unreadChar [^int c]) + (^void unreadChars [^chars buffer ^int off ^int bufflen]) + (^java.io.Reader toReader [])) + +(deftype ReaderPBR [^PushbackReader rdr] + InternalPBR + (readChar [_] + (.read rdr)) + (readChars [_ buffer start bufflen] + (.read rdr ^chars buffer start bufflen)) + (unreadChar [_ c] + (.unread rdr c)) + (unreadChars [_ buffer start bufflen] + (.unread rdr buffer start bufflen)) + (toReader [_] + rdr)) + +(comment + (compile 'clojure.data.json) + ) + +(deftype StringPBR [^String s ^:unsynchronized-mutable ^long pos ^long len] + InternalPBR + (readChar [_] + (if (< pos len) + (let [p pos] + (set! pos (unchecked-inc pos)) + (let [c (int (.charAt s p))] + c)) + (let [i (int -1)] + i))) + (readChars [_ buffer start bufflen] + (let [remaining (- len pos) + n (Math/min remaining bufflen)] + (when (pos? n) + (let [p pos + end (+ p n)] + (set! pos end) + (.getChars ^String s p end ^chars buffer start))) + (if (pos? n) n -1))) + (unreadChar [_ _c] + (set! pos (unchecked-dec pos)) + nil) + (unreadChars [_ buffer start bufflen] + (set! pos (unchecked-subtract pos bufflen)) + nil) + (toReader [_] + (StringReader. (.subSequence s pos len)))) + +(defn- pushback-pbr + [^PushbackReader r] + (->ReaderPBR r)) + +(defn- string-pbr + [^String s] + (->StringPBR s 0 (.length s))) + ;;; JSON READER (set! *warn-on-reflection* true) @@ -50,23 +114,23 @@ ~@(when (odd? (count clauses)) [(last clauses)]))) -(defn- read-hex-char [^PushbackReader stream] +(defn- read-hex-char [^InternalPBR stream] ;; Expects to be called with the head of the stream AFTER the ;; initial "\u". Reads the next four characters from the stream. - (let [a (.read stream) - b (.read stream) - c (.read stream) - d (.read stream)] + (let [a (.readChar stream) + b (.readChar stream) + c (.readChar stream) + d (.readChar stream)] (when (or (neg? a) (neg? b) (neg? c) (neg? d)) (throw (EOFException. "JSON error (end-of-file inside Unicode character escape)"))) (let [s (str (char a) (char b) (char c) (char d))] (char (Integer/parseInt s 16))))) -(defn- read-escaped-char [^PushbackReader stream] +(defn- read-escaped-char [^InternalPBR stream] ;; Expects to be called with the head of the stream AFTER the ;; initial backslash. - (let [c (.read stream)] + (let [c (.readChar stream)] (when (neg? c) (throw (EOFException. "JSON error (end-of-file inside escaped char)"))) (codepoint-case c @@ -78,10 +142,10 @@ \t \tab \u (read-hex-char stream)))) -(defn- slow-read-string [^PushbackReader stream ^String already-read] +(defn- slow-read-string [^InternalPBR stream ^String already-read] (let [buffer (StringBuilder. already-read)] (loop [] - (let [c (.read stream)] + (let [c (.readChar stream)] (when (neg? c) (throw (EOFException. "JSON error (end-of-file inside string)"))) (codepoint-case c @@ -91,11 +155,11 @@ (do (.append buffer (char c)) (recur))))))) -(defn- read-quoted-string [^PushbackReader stream] +(defn- read-quoted-string [^InternalPBR stream] ;; Expects to be called with the head of the stream AFTER the ;; opening quotation mark. (let [buffer ^chars (char-array 64) - read (.read stream buffer 0 64) + read (.readChars stream buffer 0 64) end-index (unchecked-dec-int read)] (when (neg? read) (throw (EOFException. "JSON error (end-of-file inside string)"))) @@ -104,14 +168,14 @@ (codepoint-case c \" (let [off (unchecked-inc-int i) len (unchecked-subtract-int read off)] - (.unread stream buffer off len) + (.unreadChars stream buffer off len) (String. buffer 0 i)) \\ (let [off i len (unchecked-subtract-int read off)] - (.unread stream buffer off len) + (.unreadChars stream buffer off len) (slow-read-string stream (String. buffer 0 i))) (if (= i end-index) - (do (.unread stream c) + (do (.unreadChar stream c) (slow-read-string stream (String. buffer 0 i))) (recur (unchecked-inc-int i)))))))) @@ -127,10 +191,10 @@ (bigdec string) (Double/valueOf string))) -(defn- read-number [^PushbackReader stream bigdec?] +(defn- read-number [^InternalPBR stream bigdec?] (let [buffer (StringBuilder.) decimal? (loop [stage :minus] - (let [c (.read stream)] + (let [c (.readChar stream)] (case stage :minus (codepoint-case c @@ -168,10 +232,10 @@ (recur :exp-symbol)) ;; early exit :whitespace - (do (.unread stream c) + (do (.unreadChar stream c) false) (\, \] \} -1) - (do (.unread stream c) + (do (.unreadChar stream c) false) (throw (Exception. "JSON error (invalid number literal)"))) ;; previous character is a "0" @@ -185,10 +249,10 @@ (recur :exp-symbol)) ;; early exit :whitespace - (do (.unread stream c) + (do (.unreadChar stream c) false) (\, \] \} -1) - (do (.unread stream c) + (do (.unreadChar stream c) false) ;; Disallow zero-padded numbers or invalid characters (throw (Exception. "JSON error (invalid number literal)"))) @@ -210,10 +274,10 @@ (recur :exp-symbol)) ;; early exit :whitespace - (do (.unread stream c) + (do (.unreadChar stream c) true) (\, \] \} -1) - (do (.unread stream c) + (do (.unreadChar stream c) true) (throw (Exception. "JSON error (invalid number literal)"))) ;; previous character is a "e" or "E" @@ -240,28 +304,28 @@ (do (.append buffer (char c)) (recur :exp-digit)) :whitespace - (do (.unread stream c) + (do (.unreadChar stream c) true) (\, \] \} -1) - (do (.unread stream c) + (do (.unreadChar stream c) true) (throw (Exception. "JSON error (invalid number literal)"))))))] (if decimal? (read-decimal (str buffer) bigdec?) (read-integer (str buffer))))) -(defn- next-token [^PushbackReader stream] - (loop [c (.read stream)] +(defn- next-token [^InternalPBR stream] + (loop [c (.readChar stream)] (if (< 32 c) (int c) (codepoint-case (int c) - :whitespace (recur (.read stream)) + :whitespace (recur (.readChar stream)) -1 -1)))) (defn invalid-array-exception [] (Exception. "JSON error (invalid array)")) -(defn- read-array* [^PushbackReader stream options] +(defn- read-array* [^InternalPBR stream options] ;; Handles all array values after the first. (loop [result (transient [])] (let [r (conj! result (-read stream true nil options))] @@ -270,7 +334,7 @@ \, (recur r) (throw (invalid-array-exception)))))) -(defn- read-array [^PushbackReader stream options] +(defn- read-array [^InternalPBR stream options] ;; Expects to be called with the head of the stream AFTER the ;; opening bracket. ;; Only handles array value. @@ -278,10 +342,10 @@ (codepoint-case c \] [] \, (throw (invalid-array-exception)) - (do (.unread stream c) + (do (.unreadChar stream c) (read-array* stream options))))) -(defn- read-key [^PushbackReader stream] +(defn- read-key [^InternalPBR stream] (let [c (int (next-token stream))] (if (= c (codepoint \")) (let [key (read-quoted-string stream)] @@ -292,7 +356,7 @@ nil (throw (Exception. (str "JSON error (non-string key in object), found `" (char c) "`, expected `\"`"))))))) -(defn- read-object [^PushbackReader stream options] +(defn- read-object [^InternalPBR stream options] ;; Expects to be called with the head of the stream AFTER the ;; opening bracket. (let [key-fn (get options :key-fn) @@ -317,36 +381,36 @@ (throw (Exception. "JSON error empty entry in object is not allowed")))))))) (defn- -read - [^PushbackReader stream eof-error? eof-value options] + [^InternalPBR stream eof-error? eof-value options] (let [c (int (next-token stream))] (codepoint-case c ;; Read numbers (\- \0 \1 \2 \3 \4 \5 \6 \7 \8 \9) - (do (.unread stream c) + (do (.unreadChar stream c) (read-number stream (:bigdec options))) ;; Read strings \" (read-quoted-string stream) ;; Read null as nil - \n (if (and (= (codepoint \u) (.read stream)) - (= (codepoint \l) (.read stream)) - (= (codepoint \l) (.read stream))) + \n (if (and (= (codepoint \u) (.readChar stream)) + (= (codepoint \l) (.readChar stream)) + (= (codepoint \l) (.readChar stream))) nil (throw (Exception. "JSON error (expected null)"))) ;; Read true - \t (if (and (= (codepoint \r) (.read stream)) - (= (codepoint \u) (.read stream)) - (= (codepoint \e) (.read stream))) + \t (if (and (= (codepoint \r) (.readChar stream)) + (= (codepoint \u) (.readChar stream)) + (= (codepoint \e) (.readChar stream))) true (throw (Exception. "JSON error (expected true)"))) ;; Read false - \f (if (and (= (codepoint \a) (.read stream)) - (= (codepoint \l) (.read stream)) - (= (codepoint \s) (.read stream)) - (= (codepoint \e) (.read stream))) + \f (if (and (= (codepoint \a) (.readChar stream)) + (= (codepoint \l) (.readChar stream)) + (= (codepoint \s) (.readChar stream)) + (= (codepoint \e) (.readChar stream))) false (throw (Exception. "JSON error (expected false)"))) @@ -364,16 +428,16 @@ (str "JSON error (unexpected character): " (char c)))))))) (defn- -read1 - [^PushbackReader stream eof-error? eof-value options] + [^InternalPBR stream eof-error? eof-value options] (let [val (-read stream eof-error? eof-value options)] (if-let [extra-data-fn (:extra-data-fn options)] (if (or eof-error? (not (identical? eof-value val))) - (let [c (.read stream)] + (let [c (.readChar stream)] (if (neg? c) val (do - (.unread stream c) - (extra-data-fn val stream)))) + (.unreadChar stream c) + (extra-data-fn val (.toReader stream))))) val) val))) @@ -386,7 +450,7 @@ (defn on-extra-throw-remaining "Pass as :extra-data-fn to `read` or `read-str` to throw if data is found after the first object and return the remaining data in ex-data :remaining." - [val ^java.io.PushbackReader rdr] + [val rdr] (let [remaining (slurp rdr)] (throw (ex-info (str "Found extra data after json object: " remaining) {:val val, :remaining remaining})))) @@ -443,9 +507,10 @@ [reader & {:as options}] (let [{:keys [eof-error? eof-value] :or {eof-error? true}} options - pbr (if (instance? PushbackReader reader) - reader - (PushbackReader. reader 64))] + pbr (pushback-pbr + (if (instance? PushbackReader reader) + reader + (PushbackReader. reader 64)))] (->> options (merge default-read-options) (-read1 pbr eof-error? eof-value)))) @@ -458,7 +523,7 @@ :or {eof-error? true}} options] (->> options (merge default-read-options) - (-read1 (PushbackReader. (StringReader. string) 64) eof-error? eof-value)))) + (-read1 (string-pbr string) eof-error? eof-value)))) ;;; JSON WRITER From cc154d51dc1618c107431f8560ecd80bdd7343c3 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Thu, 21 Dec 2023 11:03:00 -0600 Subject: [PATCH 32/57] cleanup --- src/main/clojure/clojure/data/json.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index 8d67418..22b454b 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/src/main/clojure/clojure/data/json.clj @@ -65,7 +65,7 @@ (unreadChar [_ _c] (set! pos (unchecked-dec pos)) nil) - (unreadChars [_ buffer start bufflen] + (unreadChars [_ _buffer _start bufflen] (set! pos (unchecked-subtract pos bufflen)) nil) (toReader [_] From d6945753218818242c844aa13bacee482a5b7232 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Thu, 21 Dec 2023 14:45:51 -0600 Subject: [PATCH 33/57] faster slow-write-string --- README.md | 2 ++ src/main/clojure/clojure/data/json.clj | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2e9135d..4671e3b 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,8 @@ Change Log * Add [DJSON-46]: In `read`, add `:extra-data-fn` that can be provided to cause an eof check after value is read * Add [DJSON-54]: In `write`, add custom fallback fn for writing unknown types * Perf [DJSON-61]: Faster string writing when string is "simple" + * Perf: Faster string writing when string is not simple + * Perf: Faster `read-str` * Release [2.4.0] on 2021-Jul-12 * Fix [DJSON-52]: Remove Classloader workaround to support Clojure 1.2.x and below * Fix [DJSON-53]: Move deprecated API functions from compat ns into main ns diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index 22b454b..aacaaba 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/src/main/clojure/clojure/data/json.clj @@ -562,14 +562,17 @@ shorts)) (defn- slow-write-string [^CharSequence s ^Appendable out options] - (let [decoder codepoint-decoder] + (let [decoder codepoint-decoder + slash (get options :escape-slash) + escape-js-separators (get options :escape-js-separators) + escape-unicode (get options :escape-unicode)] (dotimes [i (.length s)] (let [cp (int (.charAt s i))] (if (< cp 128) (case (aget decoder cp) 0 (.append out (char cp)) 1 (do (.append out (char (codepoint \\))) (.append out (char cp))) - 2 (.append out (if (get options :escape-slash) "\\/" "/")) + 2 (.append out (if slash "\\/" "/")) 3 (.append out "\\b") 4 (.append out "\\f") 5 (.append out "\\n") @@ -577,10 +580,10 @@ 7 (.append out "\\t") 8 (->hex-string out cp)) (codepoint-case cp - :js-separators (if (get options :escape-js-separators) + :js-separators (if escape-js-separators (->hex-string out cp) (.append out (char cp))) - (if (get options :escape-unicode) + (if escape-unicode (->hex-string out cp) ; Hexadecimal-escaped (.append out (char cp))))))))) From 8661733068cc29df83ce9e97f781193577541b5f Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Thu, 21 Dec 2023 17:35:05 -0600 Subject: [PATCH 34/57] DJSON-57 Throw better exception on EOF in object or array reading --- README.md | 2 ++ src/main/clojure/clojure/data/json.clj | 25 +++++++++++++++++++-- src/test/clojure/clojure/data/json_test.clj | 12 ++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4671e3b..9eb7dd5 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ Change Log * Next * Fix [DJSON-50]: `read` can take a PushbackReader for repeated read use case * Fix `write` docstring to add `:indent` option added in [DJSON-18] + * Fix [DJSON-57]: Throw better exception when EOF encountered while reading array or object * Add [DJSON-46]: In `read`, add `:extra-data-fn` that can be provided to cause an eof check after value is read * Add [DJSON-54]: In `write`, add custom fallback fn for writing unknown types * Perf [DJSON-61]: Faster string writing when string is "simple" @@ -246,6 +247,7 @@ Change Log * Source-compatible with clojure.contrib.json, except for the name change. [DJSON-61]: https://clojure.atlassian.net/browse/DJSON-61 +[DJSON-57]: https://clojure.atlassian.net/browse/DJSON-57 [DJSON-54]: https://clojure.atlassian.net/browse/DJSON-54 [DJSON-53]: https://clojure.atlassian.net/browse/DJSON-53 [DJSON-52]: https://clojure.atlassian.net/browse/DJSON-52 diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index aacaaba..e03c579 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/src/main/clojure/clojure/data/json.clj @@ -325,6 +325,9 @@ (defn invalid-array-exception [] (Exception. "JSON error (invalid array)")) +(defn- eof-array-exception [] + (EOFException. "JSON error (EOF in array)")) + (defn- read-array* [^InternalPBR stream options] ;; Handles all array values after the first. (loop [result (transient [])] @@ -332,6 +335,7 @@ (codepoint-case (int (next-token stream)) \] (persistent! r) \, (recur r) + -1 (throw (eof-array-exception)) (throw (invalid-array-exception)))))) (defn- read-array [^InternalPBR stream options] @@ -342,19 +346,35 @@ (codepoint-case c \] [] \, (throw (invalid-array-exception)) + -1 (throw (eof-array-exception)) (do (.unreadChar stream c) (read-array* stream options))))) +(defn- object-colon-exception [] + (Exception. "JSON error (missing `:` in object)")) + +(defn- eof-object-exception [] + (EOFException. "JSON error (EOF in object)")) + +(defn- invalid-key-exception [c] + (if (= c -1) + (throw (eof-object-exception)) + (throw (Exception. (str "JSON error (non-string key in object), found `" (char c) "`, expected `\"`"))))) + +(comment + (compile 'clojure.data.json) + ) + (defn- read-key [^InternalPBR stream] (let [c (int (next-token stream))] (if (= c (codepoint \")) (let [key (read-quoted-string stream)] (if (= (codepoint \:) (int (next-token stream))) key - (throw (Exception. "JSON error (missing `:` in object)")))) + (throw (object-colon-exception)))) (if (= c (codepoint \})) nil - (throw (Exception. (str "JSON error (non-string key in object), found `" (char c) "`, expected `\"`"))))))) + (invalid-key-exception c))))) (defn- read-object [^InternalPBR stream options] ;; Expects to be called with the head of the stream AFTER the @@ -374,6 +394,7 @@ (codepoint-case (int (next-token stream)) \, (recur r) \} (persistent! r) + -1 (throw (eof-object-exception)) (throw (Exception. "JSON error (missing entry in object)")))) (let [r (persistent! result)] (if (empty? r) diff --git a/src/test/clojure/clojure/data/json_test.clj b/src/test/clojure/clojure/data/json_test.clj index 8eb0354..7a82475 100644 --- a/src/test/clojure/clojure/data/json_test.clj +++ b/src/test/clojure/clojure/data/json_test.clj @@ -407,6 +407,18 @@ (is (thrown? java.io.EOFException (json/read-str "\"\\")))) +(deftest throws-eof-in-arrays + (is (thrown? java.io.EOFException + (json/read-str "[1,"))) + (is (thrown? java.io.EOFException + (json/read-str "[1,2,")))) + +(deftest throws-eof-in-objects + (is (thrown? java.io.EOFException + (json/read-str "{"))) + (is (thrown? java.io.EOFException + (json/read-str "{\"\":1,")))) + (deftest accept-eof (is (= ::eof (json/read-str "" :eof-error? false :eof-value ::eof)))) From 457b88e27d7695b38f8b3d9c737e2efb8f2b476d Mon Sep 17 00:00:00 2001 From: clojure-build Date: Fri, 22 Dec 2023 00:23:35 +0000 Subject: [PATCH 35/57] [maven-release-plugin] prepare release v2.5.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3cdaccf..3354bfc 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 data.json - 2.4.1-SNAPSHOT + 2.5.0 data.json Generating/parsing JSON from/to Clojure data structures https://github.com/clojure/data.json @@ -26,7 +26,7 @@ scm:git:git@github.com:clojure/data.json scm:git:git@github.com:clojure/data.json git@github.com:clojure/data.json.git - HEAD + v2.5.0 From 2254f09e266c0a1236fe8b56efcd73374650e484 Mon Sep 17 00:00:00 2001 From: clojure-build Date: Fri, 22 Dec 2023 00:23:35 +0000 Subject: [PATCH 36/57] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3354bfc..85e06fa 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 data.json - 2.5.0 + 2.5.1-SNAPSHOT data.json Generating/parsing JSON from/to Clojure data structures https://github.com/clojure/data.json @@ -26,7 +26,7 @@ scm:git:git@github.com:clojure/data.json scm:git:git@github.com:clojure/data.json git@github.com:clojure/data.json.git - v2.5.0 + HEAD From 77762e43992b3da485bb41d130e3b86208cf35c1 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Thu, 21 Dec 2023 22:23:50 -0600 Subject: [PATCH 37/57] update for release --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9eb7dd5..bbe33a0 100644 --- a/README.md +++ b/README.md @@ -13,23 +13,23 @@ Releases and Dependency Information This project follows the version scheme MAJOR.MINOR.PATCH where each component provides some relative indication of the size of the change, but does not follow semantic versioning. In general, all changes endeavor to be non-breaking (by moving to new names rather than by breaking existing names). -Latest stable release is [2.4.0] +Latest stable release is [2.5.0] [CLI/`deps.edn`](https://clojure.org/reference/deps_and_cli) dependency information: ```clojure -org.clojure/data.json {:mvn/version "2.4.0"} +org.clojure/data.json {:mvn/version "2.5.0"} ``` [Leiningen] dependency information: - [org.clojure/data.json "2.4.0"] + [org.clojure/data.json "2.5.0"] [Maven] dependency information: org.clojure data.json - 2.4.0 + 2.5.0 [Leiningen]: https://leiningen.org/ @@ -150,7 +150,7 @@ Developer Information Change Log ---------------------------------------- -* Next +* Release [2.5.0] on 2023-Dec-21 * Fix [DJSON-50]: `read` can take a PushbackReader for repeated read use case * Fix `write` docstring to add `:indent` option added in [DJSON-18] * Fix [DJSON-57]: Throw better exception when EOF encountered while reading array or object @@ -281,6 +281,7 @@ Change Log [DJSON-7]: https://clojure.atlassian.net/browse/DJSON-7 [DJSON-1]: https://clojure.atlassian.net/browse/DJSON-1 +[2.4.0]: https://github.com/clojure/data.json/tree/data.json-2.5.0 [2.4.0]: https://github.com/clojure/data.json/tree/data.json-2.4.0 [2.3.1]: https://github.com/clojure/data.json/tree/data.json-2.3.1 [2.3.0]: https://github.com/clojure/data.json/tree/data.json-2.3.0 From e9e57296e12750512788b723e49ba7f9abb323f9 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Mon, 19 Feb 2024 13:05:58 -0600 Subject: [PATCH 38/57] update parent pom --- pom.xml | 4 ++-- project.clj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 85e06fa..774571c 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ org.clojure pom.contrib - 1.1.0 + 1.2.0 @@ -37,7 +37,7 @@ org.clojure test.check - 1.1.0 + 1.1.1 test diff --git a/project.clj b/project.clj index b367048..825557b 100644 --- a/project.clj +++ b/project.clj @@ -7,7 +7,7 @@ :test-paths ["src/test/clojure" "src/test/clojure-perf"] :profiles {:dev {:dependencies [[com.clojure-goes-fast/clj-async-profiler "0.5.0"] [com.clojure-goes-fast/clj-java-decompiler "0.3.0"] - [org.clojure/test.check "1.1.0"] + [org.clojure/test.check "1.1.1"] [criterium/criterium "0.4.6"] [metosin/jsonista "0.3.1"] [cheshire/cheshire "5.10.0"] From 3859eaea8a0bff83d3ebeb96e3462a48965a804e Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Tue, 4 Jun 2024 11:22:24 -0500 Subject: [PATCH 39/57] Add missing readme links --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bbe33a0..9372cbe 100644 --- a/README.md +++ b/README.md @@ -255,6 +255,7 @@ Change Log [DJSON-50]: https://clojure.atlassian.net/browse/DJSON-50 [DJSON-48]: https://clojure.atlassian.net/browse/DJSON-48 [DJSON-47]: https://clojure.atlassian.net/browse/DJSON-47 +[DJSON-46]: https://clojure.atlassian.net/browse/DJSON-46 [DJSON-45]: https://clojure.atlassian.net/browse/DJSON-45 [DJSON-43]: https://clojure.atlassian.net/browse/DJSON-43 [DJSON-41]: https://clojure.atlassian.net/browse/DJSON-41 @@ -281,7 +282,7 @@ Change Log [DJSON-7]: https://clojure.atlassian.net/browse/DJSON-7 [DJSON-1]: https://clojure.atlassian.net/browse/DJSON-1 -[2.4.0]: https://github.com/clojure/data.json/tree/data.json-2.5.0 +[2.5.0]: https://github.com/clojure/data.json/tree/data.json-2.5.0 [2.4.0]: https://github.com/clojure/data.json/tree/data.json-2.4.0 [2.3.1]: https://github.com/clojure/data.json/tree/data.json-2.3.1 [2.3.0]: https://github.com/clojure/data.json/tree/data.json-2.3.0 From 9af6f1870356f050866e8591ee312a5da14f0345 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Tue, 26 Nov 2024 12:30:53 -0600 Subject: [PATCH 40/57] add buffer size constraint in read docstring --- src/main/clojure/clojure/data/json.clj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index e03c579..76a3e53 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/src/main/clojure/clojure/data/json.clj @@ -483,7 +483,8 @@ "Reads a single item of JSON data from a java.io.Reader. If you wish to repeatedly read items from the same reader, you must - supply a PushbackReader and reuse it on subsequent calls. + supply a PushbackReader with buffer size >= 64, and reuse it on + subsequent calls. Options are key-value pairs, valid options are: From 101354d9dc1fb7dd05d9737d329ac19829c8367c Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Tue, 26 Nov 2024 12:40:40 -0600 Subject: [PATCH 41/57] update changelog --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9372cbe..a4e8901 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,8 @@ Developer Information Change Log ---------------------------------------- +* next + * In `read`, update docstring to specify minimum buffer size if PushbackReader supplied * Release [2.5.0] on 2023-Dec-21 * Fix [DJSON-50]: `read` can take a PushbackReader for repeated read use case * Fix `write` docstring to add `:indent` option added in [DJSON-18] From dbff2f72118caba7f2c660a125cb81066692978c Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Tue, 26 Nov 2024 12:40:58 -0600 Subject: [PATCH 42/57] remove duplication in tests --- src/test/clojure/clojure/data/json_test.clj | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/test/clojure/clojure/data/json_test.clj b/src/test/clojure/clojure/data/json_test.clj index 7a82475..2f78fcd 100644 --- a/src/test/clojure/clojure/data/json_test.clj +++ b/src/test/clojure/clojure/data/json_test.clj @@ -3,21 +3,27 @@ [clojure.test :refer :all] [clojure.string :as str])) +(defn pbr + ([s] + (pbr s 64)) + ([s size] + (if (< size 64) + (throw (RuntimeException. "Size must be >= 64")) + (java.io.PushbackReader. (java.io.StringReader. s) size)))) + (deftest read-from-pushback-reader - (let [s (java.io.PushbackReader. (java.io.StringReader. "42"))] - (is (= 42 (json/read s))))) + (is (= 42 (json/read (pbr "42")))) + (is (= ["abc" "def"] (json/read (pbr "[\"abc\", \"def\"]"))))) -;; DJSON-50 - pass PBR to safely do reapeated read +;; DJSON-50 - pass PBR to safely do repeated read (deftest read-multiple (let [st "{\"foo\":\"some string\"}{\"foo\":\"another string\"}" - srdr (java.io.StringReader. st) - pbr (java.io.PushbackReader. srdr 64)] + pbr (pbr st)] (is (= {"foo" "some string"} (json/read pbr))) (is (= {"foo" "another string"} (json/read pbr)))) (let [st "{\"foo\":\"some string\"}{\"foo\":\"another long ......................................................... string\"}" - srdr (java.io.StringReader. st) - pbr (java.io.PushbackReader. srdr 64)] + pbr (pbr st)] (is (= {"foo" "some string"} (json/read pbr))) (is (= {"foo" "another long ......................................................... string"} (json/read pbr))))) From 45798a206304aa16b5f78e871fbe1d9d9b31732f Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Tue, 26 Nov 2024 13:22:41 -0600 Subject: [PATCH 43/57] Fix read of number followed by EOF can break subsequent read from seeing EOF --- README.md | 3 ++- src/main/clojure/clojure/data/json.clj | 18 ++++++++++++++---- src/test/clojure/clojure/data/json_test.clj | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a4e8901..0cd9fde 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,8 @@ Change Log ---------------------------------------- * next - * In `read`, update docstring to specify minimum buffer size if PushbackReader supplied + * Fix: `read` of number followed by EOF can break subsequent read from seeing EOF + * In `read`, update docstring to specify minimum buffer size when PushbackReader supplied * Release [2.5.0] on 2023-Dec-21 * Fix [DJSON-50]: `read` can take a PushbackReader for repeated read use case * Fix `write` docstring to add `:indent` option added in [DJSON-18] diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index 76a3e53..2eb1588 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/src/main/clojure/clojure/data/json.clj @@ -33,6 +33,7 @@ (readChars [_ buffer start bufflen] (.read rdr ^chars buffer start bufflen)) (unreadChar [_ c] + ;; ASSERT: c should never be -1 (EOF) (.unread rdr c)) (unreadChars [_ buffer start bufflen] (.unread rdr buffer start bufflen)) @@ -63,6 +64,7 @@ (.getChars ^String s p end ^chars buffer start))) (if (pos? n) n -1))) (unreadChar [_ _c] + ;; ASSERT: c should never be -1 (EOF) (set! pos (unchecked-dec pos)) nil) (unreadChars [_ _buffer _start bufflen] @@ -234,9 +236,11 @@ :whitespace (do (.unreadChar stream c) false) - (\, \] \} -1) + (\, \] \}) (do (.unreadChar stream c) false) + -1 + false (throw (Exception. "JSON error (invalid number literal)"))) ;; previous character is a "0" :frac-point @@ -251,9 +255,11 @@ :whitespace (do (.unreadChar stream c) false) - (\, \] \} -1) + (\, \] \}) (do (.unreadChar stream c) false) + -1 + false ;; Disallow zero-padded numbers or invalid characters (throw (Exception. "JSON error (invalid number literal)"))) ;; previous character is a "." @@ -276,9 +282,11 @@ :whitespace (do (.unreadChar stream c) true) - (\, \] \} -1) + (\, \] \}) (do (.unreadChar stream c) true) + -1 + true (throw (Exception. "JSON error (invalid number literal)"))) ;; previous character is a "e" or "E" :exp-symbol @@ -306,9 +314,11 @@ :whitespace (do (.unreadChar stream c) true) - (\, \] \} -1) + (\, \] \}) (do (.unreadChar stream c) true) + -1 + true (throw (Exception. "JSON error (invalid number literal)"))))))] (if decimal? (read-decimal (str buffer) bigdec?) diff --git a/src/test/clojure/clojure/data/json_test.clj b/src/test/clojure/clojure/data/json_test.clj index 2f78fcd..aa6d79c 100644 --- a/src/test/clojure/clojure/data/json_test.clj +++ b/src/test/clojure/clojure/data/json_test.clj @@ -27,6 +27,24 @@ (is (= {"foo" "some string"} (json/read pbr))) (is (= {"foo" "another long ......................................................... string"} (json/read pbr))))) +(defn read-then-eof [s] + (let [r (pbr s) + val (json/read r :eof-error? false :eof-value :EOF)] + (is (= :EOF (json/read r :eof-error? false :eof-value :EOF))) + val)) + +(deftest read-multiple-eof + (are [expected s] (= expected (read-then-eof s)) + 1.2 "1.2" + 0 "0" + 1 "1" + 1.0 "1.0" + "abc" "\"abc\"" + "\u2202" "\"\u2202\"" + [] "[]" + [1 2] "[1, 2]") + ) + (deftest read-from-reader (let [s (java.io.StringReader. "42")] (is (= 42 (json/read s))))) From b5a5898fe49c0412732a5784cd01a60b1e7f29ca Mon Sep 17 00:00:00 2001 From: clojure-build Date: Tue, 26 Nov 2024 19:27:17 +0000 Subject: [PATCH 44/57] [maven-release-plugin] prepare release v2.5.1 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 774571c..201c6cc 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 data.json - 2.5.1-SNAPSHOT + 2.5.1 data.json Generating/parsing JSON from/to Clojure data structures https://github.com/clojure/data.json @@ -26,7 +26,7 @@ scm:git:git@github.com:clojure/data.json scm:git:git@github.com:clojure/data.json git@github.com:clojure/data.json.git - HEAD + v2.5.1 From d9309fba2f89c2e259905229d7f40c3bf49ad27d Mon Sep 17 00:00:00 2001 From: clojure-build Date: Tue, 26 Nov 2024 19:27:17 +0000 Subject: [PATCH 45/57] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 201c6cc..f02b512 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 data.json - 2.5.1 + 2.5.2-SNAPSHOT data.json Generating/parsing JSON from/to Clojure data structures https://github.com/clojure/data.json @@ -26,7 +26,7 @@ scm:git:git@github.com:clojure/data.json scm:git:git@github.com:clojure/data.json git@github.com:clojure/data.json.git - v2.5.1 + HEAD From 300886647b53bea76c5ea097f9322656ee4ba4b9 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Tue, 26 Nov 2024 13:34:30 -0600 Subject: [PATCH 46/57] update for release --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0cd9fde..889fe37 100644 --- a/README.md +++ b/README.md @@ -13,23 +13,23 @@ Releases and Dependency Information This project follows the version scheme MAJOR.MINOR.PATCH where each component provides some relative indication of the size of the change, but does not follow semantic versioning. In general, all changes endeavor to be non-breaking (by moving to new names rather than by breaking existing names). -Latest stable release is [2.5.0] +Latest stable release is [2.5.1] [CLI/`deps.edn`](https://clojure.org/reference/deps_and_cli) dependency information: ```clojure -org.clojure/data.json {:mvn/version "2.5.0"} +org.clojure/data.json {:mvn/version "2.5.1"} ``` [Leiningen] dependency information: - [org.clojure/data.json "2.5.0"] + [org.clojure/data.json "2.5.1"] [Maven] dependency information: org.clojure data.json - 2.5.0 + 2.5.1 [Leiningen]: https://leiningen.org/ @@ -150,7 +150,7 @@ Developer Information Change Log ---------------------------------------- -* next +* Release [2.5.1] on 2024-Nov-26 * Fix: `read` of number followed by EOF can break subsequent read from seeing EOF * In `read`, update docstring to specify minimum buffer size when PushbackReader supplied * Release [2.5.0] on 2023-Dec-21 @@ -285,6 +285,7 @@ Change Log [DJSON-7]: https://clojure.atlassian.net/browse/DJSON-7 [DJSON-1]: https://clojure.atlassian.net/browse/DJSON-1 +[2.5.1]: https://github.com/clojure/data.json/tree/data.json-2.5.1 [2.5.0]: https://github.com/clojure/data.json/tree/data.json-2.5.0 [2.4.0]: https://github.com/clojure/data.json/tree/data.json-2.4.0 [2.3.1]: https://github.com/clojure/data.json/tree/data.json-2.3.1 From 711b9cdb81fd6677122a53e30aa3660c9eef656a Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Tue, 26 Nov 2024 13:37:30 -0600 Subject: [PATCH 47/57] update changelog --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 889fe37..2a849da 100644 --- a/README.md +++ b/README.md @@ -151,8 +151,8 @@ Change Log ---------------------------------------- * Release [2.5.1] on 2024-Nov-26 - * Fix: `read` of number followed by EOF can break subsequent read from seeing EOF - * In `read`, update docstring to specify minimum buffer size when PushbackReader supplied + * Fix: `read` of JSON number followed by EOF can break subsequent read on supplier PBR from seeing EOF + * Fix: `read` docstring updated to specify minimum buffer size when PushbackReader supplied (64) * Release [2.5.0] on 2023-Dec-21 * Fix [DJSON-50]: `read` can take a PushbackReader for repeated read use case * Fix `write` docstring to add `:indent` option added in [DJSON-18] From 7d5e30d731e279dfcb2e9867c9373060aaa9c6a1 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Tue, 26 Nov 2024 13:38:42 -0600 Subject: [PATCH 48/57] fix markdown tag links --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2a849da..3503642 100644 --- a/README.md +++ b/README.md @@ -285,16 +285,16 @@ Change Log [DJSON-7]: https://clojure.atlassian.net/browse/DJSON-7 [DJSON-1]: https://clojure.atlassian.net/browse/DJSON-1 -[2.5.1]: https://github.com/clojure/data.json/tree/data.json-2.5.1 -[2.5.0]: https://github.com/clojure/data.json/tree/data.json-2.5.0 -[2.4.0]: https://github.com/clojure/data.json/tree/data.json-2.4.0 -[2.3.1]: https://github.com/clojure/data.json/tree/data.json-2.3.1 -[2.3.0]: https://github.com/clojure/data.json/tree/data.json-2.3.0 -[2.2.3]: https://github.com/clojure/data.json/tree/data.json-2.2.3 -[2.2.2]: https://github.com/clojure/data.json/tree/data.json-2.2.2 -[2.2.1]: https://github.com/clojure/data.json/tree/data.json-2.2.1 -[2.2.0]: https://github.com/clojure/data.json/tree/data.json-2.2.0 -[2.1.1]: https://github.com/clojure/data.json/tree/data.json-2.1.1 +[2.5.1]: https://github.com/clojure/data.json/tree/v2.5.1 +[2.5.0]: https://github.com/clojure/data.json/tree/v2.5.0 +[2.4.0]: https://github.com/clojure/data.json/tree/v2.4.0 +[2.3.1]: https://github.com/clojure/data.json/tree/v2.3.1 +[2.3.0]: https://github.com/clojure/data.json/tree/v2.3.0 +[2.2.3]: https://github.com/clojure/data.json/tree/v2.2.3 +[2.2.2]: https://github.com/clojure/data.json/tree/v2.2.2 +[2.2.1]: https://github.com/clojure/data.json/tree/v2.2.1 +[2.2.0]: https://github.com/clojure/data.json/tree/v2.2.0 +[2.1.1]: https://github.com/clojure/data.json/tree/v2.1.1 [2.1.0]: https://github.com/clojure/data.json/tree/data.json-2.1.0 [2.0.2]: https://github.com/clojure/data.json/tree/data.json-2.0.2 [2.0.1]: https://github.com/clojure/data.json/tree/data.json-2.0.1 From 60dde602ee7d435d238c8d077c0424084e519db9 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Wed, 27 Nov 2024 13:05:29 -0600 Subject: [PATCH 49/57] update deps in benchmark test --- project.clj | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/project.clj b/project.clj index 825557b..20eb8ba 100644 --- a/project.clj +++ b/project.clj @@ -1,20 +1,19 @@ ;; NOTE: Used only for perf testing - this project is built with Maven (see pom.xml) (defproject clojure.data.json "1.1.1-SNAPSHOT" - :dependencies [[org.clojure/clojure "1.10.3"]] + :dependencies [[org.clojure/clojure "1.12.0"]] :source-paths ["src/main/clojure"] :java-source-paths ["src/main/java"] :java-test-paths ["src/test/java"] :test-paths ["src/test/clojure" "src/test/clojure-perf"] - :profiles {:dev {:dependencies [[com.clojure-goes-fast/clj-async-profiler "0.5.0"] - [com.clojure-goes-fast/clj-java-decompiler "0.3.0"] + :profiles {:dev {:dependencies [[com.clojure-goes-fast/clj-async-profiler "1.5.1"] + [com.clojure-goes-fast/clj-java-decompiler "0.3.6"] [org.clojure/test.check "1.1.1"] [criterium/criterium "0.4.6"] - [metosin/jsonista "0.3.1"] - [cheshire/cheshire "5.10.0"] - [org.openjdk.jmh/jmh-core "1.28"] - [jmh-clojure "0.4.0"] + [metosin/jsonista "0.3.12"] + [cheshire/cheshire "5.13.0"] + [org.openjdk.jmh/jmh-core "1.37"] + [jmh-clojure "0.4.1"] [com.jsoniter/jsoniter "0.9.23"]] :resource-paths ["dev-resources"] :global-vars {*warn-on-reflection* true}}} - ;;:plugins [[lein-nodisassemble "0.1.3"]] :jvm-opts ["-Djdk.attach.allowAttachSelf=true"]) From 09d6fafb09462ab4c7f9a46e6a478f893907e529 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Wed, 27 Nov 2024 14:32:21 -0600 Subject: [PATCH 50/57] DJSON-56 - in nextToken let invalid char < 32 flow out to specific parsers for better errors --- README.md | 3 +++ src/main/clojure/clojure/data/json.clj | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3503642..fe17344 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,8 @@ Developer Information Change Log ---------------------------------------- +* Next + * Fix: [DJSON-56] During `read`, better error messages for chars < 32 * Release [2.5.1] on 2024-Nov-26 * Fix: `read` of JSON number followed by EOF can break subsequent read on supplier PBR from seeing EOF * Fix: `read` docstring updated to specify minimum buffer size when PushbackReader supplied (64) @@ -251,6 +253,7 @@ Change Log [DJSON-61]: https://clojure.atlassian.net/browse/DJSON-61 [DJSON-57]: https://clojure.atlassian.net/browse/DJSON-57 +[DJSON-56]: https://clojure.atlassian.net/browse/DJSON-56 [DJSON-54]: https://clojure.atlassian.net/browse/DJSON-54 [DJSON-53]: https://clojure.atlassian.net/browse/DJSON-53 [DJSON-52]: https://clojure.atlassian.net/browse/DJSON-52 diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index 2eb1588..8afcd14 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/src/main/clojure/clojure/data/json.clj @@ -330,7 +330,7 @@ (int c) (codepoint-case (int c) :whitespace (recur (.readChar stream)) - -1 -1)))) + c)))) (defn invalid-array-exception [] (Exception. "JSON error (invalid array)")) From f3cc3bda6b6d9bdcde0034e60ba4ebcc3aefeed0 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Fri, 30 May 2025 15:03:23 -0500 Subject: [PATCH 51/57] update to new parent pom --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f02b512..8e95317 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ org.clojure pom.contrib - 1.2.0 + 1.3.0 From 369efc56ab5f3f59955d2cc38bb437161a6da8f9 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Fri, 24 Oct 2025 13:25:15 -0500 Subject: [PATCH 52/57] Update README.md Add breaking change note in the changelog for 2.0.0 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index fe17344..6ff34a6 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,7 @@ Change Log * Perf [DJSON-35]: Replace PrintWriter with more generic Appendable, reduce wrapping * Perf [DJSON-34]: More efficient writing for common path * Perf [DJSON-32]: Use option map instead of dynamic variables (affects read+write) + * NOTE: Includes a breaking change in the internal JSONWriter protocol method signature * Perf [DJSON-33]: Improve speed of reading JSON strings * Fix [DJSON-30]: Fix bad test * Release [1.1.0] on 2021-Mar-5 From 3d41c3af5d4d2b5e9acaf68945c44c202c3d609e Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Fri, 2 Jan 2026 08:33:39 -0600 Subject: [PATCH 53/57] update permissions in workflows --- .github/workflows/doc-build.yml | 3 +++ .github/workflows/release.yml | 3 +++ .github/workflows/snapshot.yml | 3 +++ .github/workflows/test.yml | 3 +++ 4 files changed, 12 insertions(+) diff --git a/.github/workflows/doc-build.yml b/.github/workflows/doc-build.yml index e379e5d..07265e0 100644 --- a/.github/workflows/doc-build.yml +++ b/.github/workflows/doc-build.yml @@ -1,5 +1,8 @@ name: Build API Docs +permissions: + contents: write + on: workflow_dispatch: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e2718bd..286cf95 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,8 @@ name: Release on demand +permissions: + contents: write + on: workflow_dispatch: inputs: diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index 2472957..9fdad8c 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -1,5 +1,8 @@ name: Snapshot on demand +permissions: + contents: read + on: [workflow_dispatch] jobs: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1fa127c..2cc441a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,8 @@ name: Test +permissions: + contents: read + on: [push] jobs: From 12574f110ef7ac4591ca64c71a4bfcc144b3f7e7 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Fri, 2 Jan 2026 08:39:52 -0600 Subject: [PATCH 54/57] update to latest parent pom --- README.md | 12 +++++++----- deps.edn | 2 +- pom.xml | 10 +++++----- project.clj | 12 ++++++------ 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 6ff34a6..653f3e2 100644 --- a/README.md +++ b/README.md @@ -13,23 +13,23 @@ Releases and Dependency Information This project follows the version scheme MAJOR.MINOR.PATCH where each component provides some relative indication of the size of the change, but does not follow semantic versioning. In general, all changes endeavor to be non-breaking (by moving to new names rather than by breaking existing names). -Latest stable release is [2.5.1] +Latest stable release is [2.5.2] [CLI/`deps.edn`](https://clojure.org/reference/deps_and_cli) dependency information: ```clojure -org.clojure/data.json {:mvn/version "2.5.1"} +org.clojure/data.json {:mvn/version "2.5.2"} ``` [Leiningen] dependency information: - [org.clojure/data.json "2.5.1"] + [org.clojure/data.json "2.5.2"] [Maven] dependency information: org.clojure data.json - 2.5.1 + 2.5.2 [Leiningen]: https://leiningen.org/ @@ -150,7 +150,8 @@ Developer Information Change Log ---------------------------------------- -* Next +* Release [2.5.2] on 2026-Jan-02 + * Update to latest parent pom and Clojure 1.11.4 * Fix: [DJSON-56] During `read`, better error messages for chars < 32 * Release [2.5.1] on 2024-Nov-26 * Fix: `read` of JSON number followed by EOF can break subsequent read on supplier PBR from seeing EOF @@ -289,6 +290,7 @@ Change Log [DJSON-7]: https://clojure.atlassian.net/browse/DJSON-7 [DJSON-1]: https://clojure.atlassian.net/browse/DJSON-1 +[2.5.2]: https://github.com/clojure/data.json/tree/v2.5.2 [2.5.1]: https://github.com/clojure/data.json/tree/v2.5.1 [2.5.0]: https://github.com/clojure/data.json/tree/v2.5.0 [2.4.0]: https://github.com/clojure/data.json/tree/v2.4.0 diff --git a/deps.edn b/deps.edn index eff4f54..1fafc86 100644 --- a/deps.edn +++ b/deps.edn @@ -1,2 +1,2 @@ {:paths ["src/main/clojure"] - :deps {org.clojure/clojure {:mvn/version "1.9.0"}}} + :deps {org.clojure/clojure {:mvn/version "1.11.4"}}} diff --git a/pom.xml b/pom.xml index 8e95317..991ac1d 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ org.clojure pom.contrib - 1.3.0 + 1.4.0 @@ -30,14 +30,14 @@ - 1.9.0 + 1.11.4 org.clojure test.check - 1.1.1 + 1.1.3 test @@ -71,7 +71,7 @@ maven-jar-plugin - 3.0.2 + 3.5.0 default-jar @@ -89,7 +89,7 @@ maven-assembly-plugin - 3.0.0 + 3.8.0 aot-jar diff --git a/project.clj b/project.clj index 20eb8ba..17f63e4 100644 --- a/project.clj +++ b/project.clj @@ -1,16 +1,16 @@ ;; NOTE: Used only for perf testing - this project is built with Maven (see pom.xml) (defproject clojure.data.json "1.1.1-SNAPSHOT" - :dependencies [[org.clojure/clojure "1.12.0"]] + :dependencies [[org.clojure/clojure "1.12.4"]] :source-paths ["src/main/clojure"] :java-source-paths ["src/main/java"] :java-test-paths ["src/test/java"] :test-paths ["src/test/clojure" "src/test/clojure-perf"] - :profiles {:dev {:dependencies [[com.clojure-goes-fast/clj-async-profiler "1.5.1"] - [com.clojure-goes-fast/clj-java-decompiler "0.3.6"] - [org.clojure/test.check "1.1.1"] + :profiles {:dev {:dependencies [[com.clojure-goes-fast/clj-async-profiler "1.6.2"] + [com.clojure-goes-fast/clj-java-decompiler "0.3.7"] + [org.clojure/test.check "1.1.3"] [criterium/criterium "0.4.6"] - [metosin/jsonista "0.3.12"] - [cheshire/cheshire "5.13.0"] + [metosin/jsonista "0.3.13"] + [cheshire/cheshire "6.1.0"] [org.openjdk.jmh/jmh-core "1.37"] [jmh-clojure "0.4.1"] [com.jsoniter/jsoniter "0.9.23"]] From 0421f0098608e8b4cc6c23802dcfa22389278f1d Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Fri, 2 Jan 2026 08:46:17 -0600 Subject: [PATCH 55/57] make empty javadoc jar --- pom.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pom.xml b/pom.xml index 991ac1d..187b814 100644 --- a/pom.xml +++ b/pom.xml @@ -85,6 +85,19 @@ + + javadoc-jar + package + + jar + + + javadoc + + **/*.html + + + From 1fce9070ee851f49a6c4ce6e1c0bb0db4d7594a0 Mon Sep 17 00:00:00 2001 From: clojure-build Date: Fri, 2 Jan 2026 14:47:36 +0000 Subject: [PATCH 56/57] [maven-release-plugin] prepare release v2.5.2 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 187b814..130cac9 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 data.json - 2.5.2-SNAPSHOT + 2.5.2 data.json Generating/parsing JSON from/to Clojure data structures https://github.com/clojure/data.json @@ -26,7 +26,7 @@ scm:git:git@github.com:clojure/data.json scm:git:git@github.com:clojure/data.json git@github.com:clojure/data.json.git - HEAD + v2.5.2 From 94463ffb54482427fd9b31f264b06bff6dcfd557 Mon Sep 17 00:00:00 2001 From: clojure-build Date: Fri, 2 Jan 2026 14:47:36 +0000 Subject: [PATCH 57/57] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 130cac9..7af80aa 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 data.json - 2.5.2 + 2.5.3-SNAPSHOT data.json Generating/parsing JSON from/to Clojure data structures https://github.com/clojure/data.json @@ -26,7 +26,7 @@ scm:git:git@github.com:clojure/data.json scm:git:git@github.com:clojure/data.json git@github.com:clojure/data.json.git - v2.5.2 + HEAD