You could use the :default option of the edn-reader e.g (import 'clojure.lang.Reflector) (defn- read-extended-ctor [class map] (Reflector/invokeStaticMethod (Class/forName (name class)) "create" (object-array [map])))
(defrecord x [a b]) (edn/read-string {:default read-extended-ctor} "#user.x{:b 2}") ;=> #user.x{:a nil :b 2} Joachim De Beule writes: > Dear Nicola, Meikel, > > Thanks for the quick replies! But is there a way to get at all reader forms > recognized by clojure.core/read-string automatically, so that I don't have > to do the bookkeeping of readers myself whenever I define a novel record > etc? > Of course, I could define my own 'defrecord-and-edn-reader' macro, but this > seems a bit overkill? > > Joachim. > > Op maandag 9 september 2013 14:30:20 UTC+2 schreef Meikel Brandmeyer > (kotarak): >> >> Hi, >> >> Am Montag, 9. September 2013 14:21:12 UTC+2 schrieb Joachim De Beule: >>> >>> So my questions are: >>> >>> 1) Is it really required that any non-standard reader-forms are passed to >>> clojure.tools.reader.edn/read-str >>> (via the :readers option)? and >>> >>> 2) If so, how do I get to the reader-forms of clojure.core/read-str, e.g. >>> for reading records? >>> >>> >> I don't know about the first, but second should be quite easy: (edn/read >> {:readers {'test.X map->X}} <input>). >> >> 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.