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

Custom java object serialization #5

Closed alolis closed 11 years ago

alolis commented 11 years ago

Hello,

I am trying to serialize a custom java object and, of course, i am getting

Caused by: java.lang.IllegalArgumentException: No method in multimethod 'print-dup' for dispatch value

Is there a recommended way with nippy to serialize custom objects or do i need to defmethod print-dup MyObject to make this work?

Thank you for your time

ptaoussanis commented 11 years ago

Hi Alexander,

Nippy serializes in two ways:

  1. Via a fast, binary serialization when available for the data type. Most standard Clojure types have a built-in implementation.
  2. As a fallback, via the Clojure Reader.

(1) Isn't actually extensible atm for the following reasons:

So in your case, basically, you will want to look at extending the Reader. Nippy will then use the appropriate Reader extension via its fallback mechanism. Some resources: https://github.com/clojure/clojure/blob/master/src/clj/clojure/uuid.clj http://www.infoq.com/interviews/hickey-clojure-reader https://github.com/clojure/clojure/blob/master/changes.md#21-reader-literals

Note that the extensible Reader requires Clojure 1.4+.

Hope that helps! Cheers :-)

alolis commented 11 years ago

Thanks a lot for the info. I will see how I will handle this :)