From fdbe43b683ebb42c0e9e939c85b6cd124b616da9 Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Wed, 30 Oct 2024 08:18:22 +0200 Subject: [PATCH 1/3] deps: bump to clojure 1.12 --- project.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project.clj b/project.clj index d40d905..5ce6132 100644 --- a/project.clj +++ b/project.clj @@ -20,8 +20,8 @@ :dependencies [[com.fasterxml.jackson.core/jackson-core "2.17.2"] [com.fasterxml.jackson.core/jackson-databind "2.17.2"] [com.fasterxml.jackson.datatype/jackson-datatype-jsr310 "2.17.2"]] - :profiles {:provided {:dependencies [[org.clojure/clojure "1.11.3"]]} - :dev {:dependencies [[org.clojure/clojure "1.11.3"] + :profiles {:provided {:dependencies [[org.clojure/clojure "1.12.0"]]} + :dev {:dependencies [[org.clojure/clojure "1.12.0"] [jmh-clojure/jmh-clojure "0.4.1"] [com.fasterxml.jackson.datatype/jackson-datatype-joda "2.17.2"] [cheshire "5.13.0"] From d73fa7ce21b7690f5e1a04e808d98f6ec45c0c86 Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Wed, 30 Oct 2024 08:27:17 +0200 Subject: [PATCH 2/3] ci: fix names of profiles: we test on clj 1.11 in addition to 1.12 --- project.clj | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/project.clj b/project.clj index 5ce6132..1b78698 100644 --- a/project.clj +++ b/project.clj @@ -34,12 +34,11 @@ [com.clojure-goes-fast/clj-async-profiler "1.2.2"] [criterium "0.4.6"]] :global-vars {*warn-on-reflection* true}} - :1.8 {:dependencies [[org.clojure/clojure "1.11.3"]]} - :1.9 {:dependencies [[org.clojure/clojure "1.11.3"]]} + :1.11 {:dependencies [[org.clojure/clojure "1.11.3"]]} :jmh {:jvm-opts ["-Dclojure.compiler.direct-linking=true"]} :perf {:jvm-opts ^:replace ["-server" "-Xmx4096m" "-Dclojure.compiler.direct-linking=true"]}} - :aliases {"all" ["with-profile" "default:dev:default:dev,1.8:dev,1.9"] + :aliases {"all" ["with-profile" "default:dev:default:dev,1.11"] "perf" ["with-profile" "default,dev,perf"] "repl" ["with-profile" "default,dev" "repl"]}) From 6245c6eefe69ed515372361c44751b057922f10b Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Wed, 30 Oct 2024 08:18:38 +0200 Subject: [PATCH 3/3] fix: delay serialization on clojure 1.12 fixes #83 --- src/clj/jsonista/core.clj | 4 +++- .../jsonista/jackson/DelaySerializer.java | 24 +++++++++++++++++++ test/jsonista/core_test.clj | 12 ++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/java/jsonista/jackson/DelaySerializer.java diff --git a/src/clj/jsonista/core.clj b/src/clj/jsonista/core.clj index e93a3ae..26ca29d 100644 --- a/src/clj/jsonista/core.clj +++ b/src/clj/jsonista/core.clj @@ -50,6 +50,7 @@ (:import (jsonista.jackson DateSerializer + DelaySerializer FunctionalKeyDeserializer FunctionalSerializer KeywordSerializer @@ -70,7 +71,7 @@ (java.net URL) (com.fasterxml.jackson.datatype.jsr310 JavaTimeModule) (java.util Iterator List Map Date) - (clojure.lang Keyword Ratio Symbol))) + (clojure.lang Delay Keyword Ratio Symbol))) (defn- ^Module clojure-module "Create a Jackson Databind module to support Clojure datastructures. @@ -87,6 +88,7 @@ (.addSerializer Date (if date-format (DateSerializer. date-format) (DateSerializer.))) + (.addSerializer Delay (DelaySerializer.)) (as-> module (doseq [[type encoder] encoders] (cond diff --git a/src/java/jsonista/jackson/DelaySerializer.java b/src/java/jsonista/jackson/DelaySerializer.java new file mode 100644 index 0000000..e9914ae --- /dev/null +++ b/src/java/jsonista/jackson/DelaySerializer.java @@ -0,0 +1,24 @@ +package jsonista.jackson; + +import clojure.lang.Delay; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; + +import java.io.IOException; + +/** Serializer that mimics the behaviour we had prior to Clojure 1.12. + The Jackson default serializer now barfs on the Delay objects after Clojure 1.12. */ +public class DelaySerializer extends StdSerializer { + + public DelaySerializer() { + super(DateSerializer.class, true); + } + + @Override + public void serialize(Delay value, JsonGenerator gen, SerializerProvider provider) throws IOException { + gen.writeStartObject(); + gen.writeBooleanField("realized", value.isRealized()); + gen.writeEndObject(); + } +} diff --git a/test/jsonista/core_test.clj b/test/jsonista/core_test.clj index e0dc128..5b54701 100644 --- a/test/jsonista/core_test.clj +++ b/test/jsonista/core_test.clj @@ -377,3 +377,15 @@ (j/write-values-as-array file eduction) (is (= expected (slurp file))) (.delete file))) + +;; clojure 1.12 seems to have changed delay so that jackson barfs on it +;; this test documents the old behaviour that we preserve with our custom DelaySerializer +(deftest test-delay + (let [d (delay 1) + d2 (delay (list :a 1))] + (is (= "{\"realized\":false}" (j/write-value-as-string d))) + (is (= "{\"realized\":false}" (j/write-value-as-string d2))) + (force d) + (force d2) + (is (= "{\"realized\":true}" (j/write-value-as-string d))) + (is (= "{\"realized\":true}" (j/write-value-as-string d2)))))