Skip to content

Commit

Permalink
[fix] [#143] Don't freeze meta info for types that don't support `wit…
Browse files Browse the repository at this point in the history
…h-meta`
  • Loading branch information
ptaoussanis committed Aug 1, 2023
1 parent 54d6967 commit 9c7b4da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/taoensso/nippy.clj
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,9 @@
(defprotocol IFreezable1 (-freeze-without-meta! [x data-output]))
(defprotocol IFreezable2 (-freeze-with-meta! [x data-output]))
(extend-protocol IFreezable2 ; Must be a separate protocol
clojure.lang.IMeta
clojure.lang.IObj ; IMeta => `meta` will work, IObj => `with-meta` will work
(-freeze-with-meta! [x ^DataOutput data-output]
(let [m (when *incl-metadata?* (.meta x))]
(let [m (when *incl-metadata?* (meta x))]
(when m
(write-id data-output id-meta)
(-freeze-without-meta! m data-output)))
Expand Down
9 changes: 8 additions & 1 deletion test/taoensso/nippy_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@

;;;; Metadata

(def my-var "Just a string")

(deftest _metadata
[(is
(:has-meta?
Expand Down Expand Up @@ -355,7 +357,12 @@
{:incl-metadata? true}
)))

"Metadata successfully excluded by freeze")])
"Metadata successfully excluded by freeze")

(is (var? (nippy/read-quarantined-serializable-object-unsafe!
(nippy/thaw (nippy/freeze #'my-var))))

"Don't try to preserve metadata on var")])

;;;; Benchmarks

Expand Down

0 comments on commit 9c7b4da

Please sign in to comment.