tailrecursion / cljson

Clojure/ClojureScript library for accelerated browser data deserialization
62 stars 4 forks source link

Can't encode SubVector #12

Open catharinejm opened 9 years ago

catharinejm commented 9 years ago
repl=> (clj->cljson (subvec [1 2 3 4] 0 2))
IllegalArgumentException No cljson encoding for '[1 2]'.  tailrecursion.cljson/encode (cljson.clj:72)

Looks like clojure.lang.PersistentVector is extended with EncodeTagged, but not clojure.lang.IPersistentVector. In my (extremely rudimentary) testing, making it IPersistentVector instead seems to work fine.

alandipert commented 9 years ago

Good catch!

Trolling around clojure.lang.RT and clojure.lang.APersistentVector$SubVector, it looks like what we want is to add an implementation for instances of clojure.lang.APersistentVector, or possibly check for APersistentVector instead of PersistentVector.

Using IPersistentVector works, but we want to avoid interfaces if we can because they might overlap.