Last Updated: August 10, 2016
·
2.708K
· jenshaase

Clojurescript, read-string and records

Currently in Clojurescript it is not possible to use cljs.reader/read-string on records. Following script will not work:

(defrecord Test [a b])
(def a (->Test 1 2))
(cljs.reader/read-string (pr-str a)) ; will not work

To fix this you can register a tagged parser to the reader:

(defrecord Test [a b])
(cljs.reader/register-tag-parser! "Test" map->Test)
(def a (->Test 1 2))
(cljs.reader/read-string (pr-str a)) ; works!