Hi, Am Donnerstag, 22. August 2013 11:32:37 UTC+2 schrieb Jim foo.bar: > > Oh wow! I shouldn't have turned my computer off yesterday evening!!! > there were many suggestions to try out... :) > > Ok let's see...I've got a record with meta-data let's call it FOO and its > instance MFOO: > > user=> (defrecord FOO [a b c]) > user.FOO > user=> (def MFOO (with-meta (FOO. 1 2 3) {:x false :y true})) > #'user/MFOO > > Now I want to serialise it but keep the meta-data when reading it back in. > pint-dup seems like my only option as it preserves metadata. As you say > though, there is no dispatch for '=' so it seems like I'm stuck with > standard java serialisation. Even i I convert it to a map with metadata the > same thing will happen (#=)... > > Is there no way to keep the metadata? > > many many thanks :) > > (defmethod print-method Foo [foo ^Writer w] (.write w "#my/foo ") (print-method {:a (:a foo) :b (:b foo) :c (:c foo) :meta (meta foo)} w))
(defn foo-reader [foo-data] (with-meta (map->Foo (dissoc foo-data :meta)) (:meta foo-data))) Read with: (edn/read {'my/foo foo-reader} ...) Printing might be optimised a bit. And the :meta key could be made more robust. (records may contain arbitrary keys.) Kind regards Meikel -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.