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

Disable metadata freezing #122

Closed kennyjwilli closed 4 years ago

kennyjwilli commented 4 years ago

Is there a way to disable the automatic freezing of metadata? Since Clojure 1.10 is out, many objects contain datafy functions. Since functions are not serializable, Nippy will throw an exception on all of these objects that looks something like this:

clojure.lang.ExceptionInfo: Unfreezable type: class clojure.core$partial$fn__5839
{:type clojure.core$partial$fn__5839, :as-str "#object[clojure.core$partial$fn__5839 0x63a4ed1e \"clojure.core$partial$fn__5839@63a4ed1e\"]"}
kennyjwilli commented 4 years ago

As a workaround, I added this:

(extend-protocol nippy/IFreezable2
  IMeta
  (-freeze-with-meta! [x ^DataOutput data-output]
    (nippy/-freeze-without-meta! x data-output)))

Ideally there would be an option I could pass to freeze to disable this.

atdixon commented 4 years ago

I'm interested in this capability as well - for a different reason.

I sought to serialize a Clojure Var (which is both Serializable and IMeta), but while nippy can successfully serialize, it fails to deserialize the bytes b/c Var is an unconventional IMeta that does not implement IObj:

The failure is easy to reproduce:

(defn my-fn [])
(nippy/thaw (nippy/freeze #'my-fn))
Execution error (ClassCastException) at taoensso.nippy/thaw-from-in! (nippy.clj:1136).
clojure.lang.Var cannot be cast to clojure.lang.IObj

For my purposes I do not need the metadata to carry with the serialization, so an option for disabling metadata freezing would be ideal for me as well. (Just to offer another use case here.)

ptaoussanis commented 4 years ago

Option for this incoming shortly. Will allow disabling metadata on individual freeze or thaw calls.