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))))
This commit is contained in:
parent
d0eb2d9871
commit
2c8663d23b
2 changed files with 6 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue