     (binding [*handlers* (merge default-handlers handlers)]
       (marshal-top m o (write-cache)))
     ;; can we configure JsonGenerator to automatically flush writes?
-    (flush-writer m)))
+    (flush-writer m (.stm writer))))
 
 (defn make-handler
   [tag-fn rep-fn str-rep-fn]

        (set! *handlers* (assoc *handlers* t h))
        h))))

(deftype Writer [marshaler opts])

(defprotocol Writerable
  (make-writer [_ type opts]))

  (emit-map-start [em size])
  (emit-map-end [em])
  (emit-quoted [em o cache])
  (flush-writer [em stm])
  (prefers-strings [em]))

(def JSON_INT_MAX (Math/pow 2 53))
