Warn about thaw-id reset at runtime rather than expansion time

This commit is contained in:
Peter Taoussanis 2015-06-01 11:09:59 +07:00
parent 82294f54f9
commit 5a623870fe

View file

@ -768,20 +768,22 @@
(->MyType (.readUTF data-input)))" (->MyType (.readUTF data-input)))"
[custom-type-id [in] & body] [custom-type-id [in] & body]
(assert-custom-type-id custom-type-id) (assert-custom-type-id custom-type-id)
(when (contains? *custom-readers* (coerce-custom-type-id custom-type-id)) `(do
(println (format "Warning: resetting Nippy thaw for custom type with id: %s" (when (contains? *custom-readers* ~(coerce-custom-type-id custom-type-id))
custom-type-id))) (println (format "Warning: resetting Nippy thaw for custom type with id: %s"
`(swap-custom-readers! ~custom-type-id)))
(fn [m#] (swap-custom-readers!
(assoc m# (fn [m#]
~(coerce-custom-type-id custom-type-id) (assoc m#
(fn [~(with-meta in {:tag 'java.io.DataInput})] ~(coerce-custom-type-id custom-type-id)
~@body))))) (fn [~(with-meta in {:tag 'java.io.DataInput})]
~@body))))))
(comment (defrecord MyType [data]) (comment
(extend-freeze MyType 1 [x out] (.writeUTF out (:data x))) (defrecord MyType [data])
(extend-thaw 1 [in] (->MyType (.readUTF in))) (extend-freeze MyType 1 [x out] (.writeUTF out (:data x)))
(thaw (freeze (->MyType "Joe")))) (extend-thaw 1 [in] (->MyType (.readUTF in)))
(thaw (freeze (->MyType "Joe"))))
;;; Some useful custom types - EXPERIMENTAL ;;; Some useful custom types - EXPERIMENTAL