Fix JRuby bug

JRuby's `copy_stream` only accepts `String` or `IO` objects so `data` has to be one of those when serializing.