Java Object Serialize serialize(T obj)

Here you can find the source of serialize(T obj)

Description

serialize

License

Open Source License

Declaration

public static <T> byte[] serialize(T obj) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.io.ObjectOutputStream;

public class Main {
    public static <T> byte[] serialize(T obj) {
        ObjectOutputStream oos = null;
        ByteArrayOutputStream os = null;
        try {//from  w w w .  j a va2s .  c om
            os = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(os);
            oos.writeObject(obj);
            return os.toByteArray();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (oos != null) {
                try {
                    os.close();
                    oos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        return null;
    }
}

Related

  1. serialize(Serializable serializable)
  2. serialize(Serializable... objects)
  3. serialize(String filename, T obj)
  4. serialize(String path, String name, Object obj)
  5. serialize(T obj)
  6. serialize(T object)
  7. serialize(T object)
  8. serialize(T object)
  9. serialize(T t)