From 2c8663d23b12d6909a5ac267aea4bee7de94ab7a Mon Sep 17 00:00:00 2001 From: Phillip Mates Date: Tue, 2 May 2023 16:15:33 +0200 Subject: [PATCH] add java.sql.Date, prevents it from being thawed as java.util.Date ;; used to fail, the thaw value was an instance of the parent `java.util.Date` class (require '[taoensso.nippy :as nippy]) (let [sql (java.sql.Date/valueOf "2023-05-01")] (is (= (type sql) (-> sql nippy/freeze nippy/thaw type)))) --- README.md | 1 + src/taoensso/nippy.clj | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index 6f1f8ae..c39738b 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ nippy/stress-data :uri (URI. "https://clojure.org/reference/data_structures") :uuid (java.util.UUID/randomUUID) :date (java.util.Date.) + :sql-date (java.sql.Date/valueOf "2023-06-21") ;;; JVM 8+ :time-instant (java.time.Instant/now) diff --git a/src/taoensso/nippy.clj b/src/taoensso/nippy.clj index 8979d1b..9bfab54 100644 --- a/src/taoensso/nippy.clj +++ b/src/taoensso/nippy.clj @@ -119,6 +119,7 @@ 90 [:date [[:bytes 8]]] 91 [:uuid [[:bytes 16]]] + 92 [:sql-date [[:bytes 8]]] ;; JVM >=8 79 [:time-instant [[:bytes 12]]] @@ -370,6 +371,7 @@ "java.net.URI" "java.util.UUID" "java.util.Date" + "java.sql.Date" #_"java.time.*" ; Safe? "java.time.Clock" @@ -1128,6 +1130,7 @@ (write-biginteger out (.denominator x))) (id-freezer Date id-date (.writeLong out (.getTime x))) +(id-freezer java.sql.Date id-sql-date (.writeLong out (.getTime x))) (id-freezer URI id-uri (write-str out (.toString x))) @@ -1693,6 +1696,7 @@ (read-biginteger in)) id-date (Date. (.readLong in)) + id-sql-date (java.sql.Date. (.readLong in)) id-uuid (UUID. (.readLong in) (.readLong in)) id-uri (URI. (thaw-from-in! in)) @@ -2064,6 +2068,7 @@ :uri (URI. "https://clojure.org/reference/data_structures") :uuid (java.util.UUID/randomUUID) :date (java.util.Date.) + :sql-date (java.sql.Date/valueOf "2023-06-21") ;;; JVM 8+ :time-instant (enc/compile-if java.time.Instant (java.time.Instant/now) nil)