Here you can find the source of serializeTo(OutputStream outputStream, Object obj)
public static void serializeTo(OutputStream outputStream, Object obj) throws IOException
//package com.java2s; //License from project: Apache License import com.google.gson.Gson; import com.google.gson.GsonBuilder; import java.io.*; public class Main { private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); public static void serializeTo(OutputStream outputStream, Object obj) throws IOException { String json = GSON.toJson(obj); try {/*from w w w.ja v a 2 s .com*/ outputStream.write(json.getBytes()); outputStream.flush(); } finally { if (outputStream != null) { outputStream.close(); } } } }