cognitect / transit-cljs

Transit for ClojureScript
http://transit-format.org
Apache License 2.0
323 stars 20 forks source link

Vector field deserializing as JS Array #56

Closed Outrovurt closed 2 years ago

Outrovurt commented 4 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?

swannodette commented 2 years ago

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.