Closed kendagriff closed 10 years ago
So, a couple things:
clj->cljson
returns a string, not a ClojureScript vector or a JavaScript object (although it sure does look like one when printed). So, you'd only want to call cljson->clj
with a string argument.cljs.core/*data-readers*
. ClojureScript leans on Clojure's reader for compilation. However, a ClojureScript reader implementation is supplied in cljs.reader.Here's an example ClojureScript namespace to accomplish what you want:
(ns example
(:require [tailrecursion.cljson :refer [clj->cljson cljson->clj]]
[cljs.reader :refer [register-tag-parser!]]))
(defrecord Person [name])
(register-tag-parser! "example.Person" map->Person)
(print (cljson->clj (clj->cljson (Person. "Bob")))) ;=> #example.Person{:name Bob}
Please close this if your question is answered. Thanks!
Yes, that was a huge help! This would have helped in the README; shall I submit a pull request?
That would be great, thanks!
Does cljson not work for Clojurescript records?
Returns:
This seems fairly basic... am I missing anything?