   ([out type] (writer out type {}))
   ([^OutputStream out type {:keys [handlers]}]
      (if (#{:json :json-verbose :msgpack} type)
-       (let [handler-map (if (instance? WriteHandlerMap handlers) handlers (merge default-write-handlers handlers))]
+       (let [handler-map (if (instance? HandlerMapContainer handlers)
+                           (handler-map handlers)
+                           (merge default-write-handlers handlers))]
          (Writer. (TransitFactory/writer (transit-format type) out handler-map)))
        (throw (ex-info "Type must be :json, :json-verbose or :msgpack" {:type type})))))
 

  ([in type] (reader in type {}))
  ([^InputStream in type {:keys [handlers default-handler]}]
     (if (#{:json :json-verbose :msgpack} type)
       (let [handler-map (if (instance? ReadHandlerMap handlers) handlers (merge default-read-handlers handlers))
             reader (TransitFactory/reader (transit-format type)
                                           in
                                           handler-map

           [com.cognitect.transit.impl ReadHandlerMap WriteHandlerMap]
           [com.cognitect.transit.SPI ReaderSPI]
           [java.io InputStream OutputStream]))

(defprotocol HandlerMapProvider
  (handler-map [this]))

(deftype HandlerMapContainer [m]
  HandlerMapProvider
  (handler-map [this] m))

;; writing

