     (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]

     (case type
       :json (.createGenerator (JsonFactory.) stm)
       :msgpack (.createPacker (MessagePack.) stm))
     opts))
  java.io.Writer
  (make-writer [^java.io.Writer w type opts]

    (emit-string jg ESC_TAG "'" nil true cache)
    (marshal jg o false cache)
    (emit-map-end jg))
  (flush-writer [^JsonGenerator jg _] (.flush jg))
  (prefers-strings [_] true))

(def MSGPACK_INT_MAX (Math/pow 2 64))
