title: Write object to zip file in json format
body: <p>My goal is to write an object to zip file in json format. The simplest way of doing it is:</p>
  
  <pre><code>ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
  String json = gson.toJson(object);
  zip.write(json.getBytes());
  </code></pre>
  
  <p>But I want to avoid to load the whole object to a single string. So I wrapped a zip stream into a writer object:</p>
  
  <pre><code>Writer writer = new OutputStreamWriter(zip);
  </code></pre>
  
  <p>And after that I write the entry in the following way:</p>
  
  <pre><code>zip.putNextEntry(entry);
  gson.toJson(content, writer);
  writer.flush();
  zip.closeEntry();
  zip.flush();
  </code></pre>
  
  <p>It works fine, but it seems very messy using writer and zip objects at the same time. Is there any better solution for this problem?</p>