Java Object Serialize serialize(T object)

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

Description

serialize

License

Apache License

Declaration

public static <T extends Serializable> byte[] serialize(T object) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    public static <T extends Serializable> byte[] serialize(T object) {
        if (null == object)
            return null;

        ObjectOutputStream oos = null;
        ByteArrayOutputStream baos = null;

        byte[] bytes = null;
        try {/*from   w  w  w . java 2  s.  c  o  m*/
            baos = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(baos);
            oos.writeObject(object);
            bytes = baos.toByteArray();
        } catch (Exception e) {
            throw new RuntimeException("Serialize Object Filed:" + e.getMessage());
        }

        return bytes;
    }
}

Related

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