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

Working with Record #43

Closed kul closed 10 years ago

kul commented 10 years ago

How should records be de/serialized ?

user=> (defrecord MyRec [a b])
user.MyRec
user=> (n/thaw (n/freeze (MyRec. 1 2)))

ClassNotFoundException user.MyRec  java.net.URLClassLoader$1.run (URLClassLoader.java:366)

Regards

kul commented 10 years ago

Oh! just saw this https://github.com/ptaoussanis/nippy#custom-types-v21-alpha---subject-to-change

Can working with records be made more seamless?

ptaoussanis commented 10 years ago

Hi Kul, your example should work:

(defrecord MyRec [a b]) => taoensso.nippy.MyRec
(thaw (freeze (MyRec. 1 2))) => #taoensso.nippy.MyRec{:a 1, :b 2}

What version of Nippy+Clojure are you using?

kul commented 10 years ago

nippy "2.5.2" and clojure "1.4.0" , Can this still be done in 1.4.0?

ptaoussanis commented 10 years ago

Yes, should work. Just tried 2.5.2 against Clojure 1.4.0 and it works as expected:

(defrecord MyRec [a b]) => user.MyRec
(n/thaw (n/freeze (MyRec. 1 2))) => #user.MyRec{:a 1, :b 2}

This is also covered by the unit tests. I'd check that your environment is configured correctly. Try lein clean, restart your REPL, make sure your type is actually defined in the appropriate namespace. Let me know if that helps :-)

kul commented 10 years ago

This is weird freeze works correctly but thaw has problem. But this only happens in my project and works fine with lein try com.taoensso/nippy "2.5.2" outside project. This may be a jar conflict! I will close this in sometime.

Thanks

ptaoussanis commented 10 years ago

Sure, no problem. Things I would focus on checking:

  1. Have you :imported the required Record/Type into the namespace that's doing the thawing?
  2. lein clean.
  3. project AOT issues.

Hope that helps, cheers :-)

ptaoussanis commented 10 years ago

Closing this, please feel free to reopen if you're still experiencing any problems :-)