Is there a generic way to (de)serialize arrays using transit?
I find myself in this situation:
(require '[cognitect.transit :as transit])
(def array-write-handler (transit/write-handler "pod.babashka.sql/array" vec))
(def array-type (class (into-array Object [])))
(defn write-transit [v]
(let [baos (java.io.ByteArrayOutputStream.)]
(transit/write (transit/writer baos :json {:handlers {array-type array-write-handler}}) v)
(.toString baos "utf-8")))
(prn (write-transit (into-array Object ["foo"]))) ;; works
(prn (write-transit (into-array String ["foo"]))) ;; ERROR
and it looks like you have to encode serialization explicitly for every type, which can be error prone and tedious. Can I use some sort of fallback handler before transit decides it cannot encode a certain type of object? In this fallback I could check if the object is an array using .isArray?
The way I currently work around this is using walk/postwalk and make some custom representation, but this seems to defeat the purpose of transit.