Closed Outrovurt closed 2 years ago
I've created a custom type, let's call it MyType, which accepts a single vector as a field. The following code demonstrates the setup:
(deftype MyType [vc]) (def my-writer (t/writer :json {:handlers {MyType (t/write-handler (constantly "MyType") (fn [m] (.-vc m) ))}})) (def my-reader (t/reader :json {:handlers {"MyType" (t/read-handler (fn [vc] (MyType. vc)))}}))
I have absolutely no problem serializing it, but when it I try to deserialize it I get a JS Array in place of the original vector.
For example:
(->> (MyType. [:a 1 :b 2]) (t/write my-writer) (t/read my-reader) .-vc)
Results in:
#js[:a 1 :b 2]
I can easily get round this by calling js->clj to transform this back to a vector so this isn't a big issue, but I was wondering, is this actually the intended behaviour or a bug?
js->clj
transit-cljs is just a simple wrapper over a library written in JavaScript - transit-js. In the handlers you must deal the with the lower-level types.
I've created a custom type, let's call it MyType, which accepts a single vector as a field. The following code demonstrates the setup:
I have absolutely no problem serializing it, but when it I try to deserialize it I get a JS Array in place of the original vector.
For example:
Results in:
I can easily get round this by calling
js->clj
to transform this back to a vector so this isn't a big issue, but I was wondering, is this actually the intended behaviour or a bug?