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

EvalReader not allowed for thaw of java.util.Date #23

Closed joelkuiper closed 11 years ago

joelkuiper commented 11 years ago

When running thaw on java.util.Date a runtime exception is thrown in Clojure 1.5.1 and nippy 2.1.0

(require '[taoensso.nippy :as nippy])
(nippy/thaw (nippy/freeze (java.util.Date.)))
RuntimeException EvalReader not allowed when *read-eval* is false. clojure.lang.Util.runtimeException (Util.java:219)

Is there a work around for this (other than disabling the reader check?)

ptaoussanis commented 11 years ago

Hi Joël, any chance you're running Monger (a Clojure MongoDB client)?

What happens if you run (read-string (pr-str (java.util.Date.)))? What about (binding [*read-eval* false] (read-string (pr-str (java.util.Date.))))?

For safety, Nippy disables *read-eval* by default. If either of the above throw an exception then you or a library have configured the Clojure reader to print dates using a method that requires *read-eval*. Ideal solution would be to sort out the print method.

In any event, James will be bringing some changes to Nippy soon (one PR referenced above, another to add binary serialization for Dates). Not sure if the first will sort this out, but the second certainly will since it'll bypass the reader altogether.

Hope that helps! Cheers :-)

joelkuiper commented 11 years ago

@ptaoussanis Yeah I'm running Monger too however the pr-str's do not throw an error. I'll be awaiting the next release then :smile: the system is not in production yet so I can get by with setting the reader-eval for now!

ptaoussanis commented 11 years ago

Okay, I mentioned Monger because that's one of the libraries I know that can cause this problem.

In any case, just pushed v2.0.0-RC1 with James' changes. This version should completely sidestep any reader issues you're seeing.

Closing this for now; feel free to reopen if you're still running into any trouble. Cheers!