From 5a623870fe475c37a12e03e917de2b45c492e6a2 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Mon, 1 Jun 2015 11:09:59 +0700 Subject: [PATCH] Warn about thaw-id reset at runtime rather than expansion time --- src/taoensso/nippy.clj | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/taoensso/nippy.clj b/src/taoensso/nippy.clj index e7cd446..5744831 100644 --- a/src/taoensso/nippy.clj +++ b/src/taoensso/nippy.clj @@ -768,20 +768,22 @@ (->MyType (.readUTF data-input)))" [custom-type-id [in] & body] (assert-custom-type-id custom-type-id) - (when (contains? *custom-readers* (coerce-custom-type-id custom-type-id)) - (println (format "Warning: resetting Nippy thaw for custom type with id: %s" - custom-type-id))) - `(swap-custom-readers! - (fn [m#] - (assoc m# - ~(coerce-custom-type-id custom-type-id) - (fn [~(with-meta in {:tag 'java.io.DataInput})] - ~@body))))) + `(do + (when (contains? *custom-readers* ~(coerce-custom-type-id custom-type-id)) + (println (format "Warning: resetting Nippy thaw for custom type with id: %s" + ~custom-type-id))) + (swap-custom-readers! + (fn [m#] + (assoc m# + ~(coerce-custom-type-id custom-type-id) + (fn [~(with-meta in {:tag 'java.io.DataInput})] + ~@body)))))) -(comment (defrecord MyType [data]) - (extend-freeze MyType 1 [x out] (.writeUTF out (:data x))) - (extend-thaw 1 [in] (->MyType (.readUTF in))) - (thaw (freeze (->MyType "Joe")))) +(comment + (defrecord MyType [data]) + (extend-freeze MyType 1 [x out] (.writeUTF out (:data x))) + (extend-thaw 1 [in] (->MyType (.readUTF in))) + (thaw (freeze (->MyType "Joe")))) ;;; Some useful custom types - EXPERIMENTAL