taoensso / nippy

The fastest serialization library for Clojure
https://www.taoensso.com/nippy
Eclipse Public License 1.0
1.04k stars 60 forks source link

:read-eval? true causes error on deftyped types with custom print-dup #18

Closed exi closed 11 years ago

exi commented 11 years ago

thawing with :read-eval? true seems to lead to an error if i use custom types with custom print-dup:

Here my small example code:

(deftype MyType [a b c])
(defn new-type [a b c] (MyType. a b c))
(defmethod print-method MyType 
  [t writer] 
  (.write writer (str "#user.new-type[" (.a t) " " (.b t) " " (.c t)"]")))
(defmethod print-dup MyType 
  [t writer] 
  (.write writer (str "#=(user/new-type " (.a t) " " (.b t) " " (.c t) ")")))
(binding [*print-dup* true] 
  (read-string (pr-str (new-type 1 2 3))))
;; #user.new-type[1 2 3]
(nippy/thaw (nippy/freeze (new-type 1 2 3)) :read-eval? true)
; Quit to level 1
; Evaluation aborted
ptaoussanis commented 11 years ago

Hi Reno,

This looks like a simple arg typo. Try (nippy/thaw (nippy/freeze (new-type 1 2 3)) {:read-eval? true}) instead of (nippy/thaw (nippy/freeze (new-type 1 2 3)) :read-eval? true). I.e. the thaw args need to be enclosed in a map.

Does that help?

exi commented 11 years ago

Never write bug reports before drinking your first cup of coffee ^^ I'm sorry, of course it was a typo.

ptaoussanis commented 11 years ago

Absolutely no problem, it's an easy mistake to make. Glad there was a simple solution :-)

Cheers!