Closed weavejester closed 11 years ago
The IPersistentMap interface is implemented by records as well as normal map structures, so when serializing records Nippy incorrectly encodes them as maps.
IPersistentMap
user=> (require '[taoensso.nippy :as nippy]) nil user=> (defrecord Foo [x]) user.Foo user=> (nippy/thaw (nippy/freeze (Foo. 1))) {:x 1}
The APersistentMap abstract class, on the other hand, is implemented by all map types except for records:
APersistentMap
user=> (instance? clojure.lang.APersistentMap (hash-map)) true user=> (instance? clojure.lang.APersistentMap (array-map)) true user=> (instance? clojure.lang.APersistentMap (sorted-map)) true user=> (instance? clojure.lang.APersistentMap (Foo. 1)) false
For this reason it's better for Nippy to dispatch its freezer off of APersistentMap instead of IPersistentMap.
The
IPersistentMap
interface is implemented by records as well as normal map structures, so when serializing records Nippy incorrectly encodes them as maps.The
APersistentMap
abstract class, on the other hand, is implemented by all map types except for records:For this reason it's better for Nippy to dispatch its freezer off of
APersistentMap
instead ofIPersistentMap
.