code: public static void serialize(OutputStream out, @Nonnull  JsonElement json, boolean pretty) throws IOException {
          Validate.notNull(out);
          BufferedOutputStream bufferedOut = new BufferedOutputStream(out);
          OutputStreamWriter w = new OutputStreamWriter(bufferedOut, UTF8);
          if(pretty) {
              serialize(w, json, pretty);
          } else {
              json.serialize(w);
              // subtle bug where not flushing this results in empty string when serializing to a ByteArrayOutputStream
              w.flush();
              bufferedOut.flush();
          }
      }
docs: Writes the object out as json.
  
  @param out
  output writer
  @param json
  a {@link JsonElement}
  @param pretty
  if true, a properly indented version of the json is written
  @throws IOException
  if there is a problem writing to the stream