Java OutputStream Write serializeTo(OutputStream outputStream, Object obj)

Here you can find the source of serializeTo(OutputStream outputStream, Object obj)

Description

serialize To

License

Apache License

Declaration

public static void serializeTo(OutputStream outputStream, Object obj) throws IOException 

Method Source Code


//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();
            }
        }
    }
}

Related

  1. serializeObject(OutputStream out, Object o)
  2. serializeShortLE(short value, OutputStream outStream)
  3. serializeSpecial(OutputStream os, Serializable obj)
  4. serializeString(OutputStream out, String data)
  5. serializeString(String str, DataOutputStream dout)
  6. serializeToOutputStream(final Serializable ser, final OutputStream os)
  7. serializeUUID(OutputStream out, UUID id)
  8. writeStream(byte[] data, OutputStream os)
  9. writeStream(byte[] data, OutputStream out)