Java Object Serialize serialize(Object object)

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

Description

serialize

License

Open Source License

Declaration

public static byte[] serialize(Object object) 

Method Source Code


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

import java.io.*;

public class Main {
    public static byte[] serialize(Object object) {
        if (object == null) {
            return null;
        }//from w  w  w.j  a  va 2 s . co  m
        ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
        try {
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(object);
            oos.flush();
        } catch (IOException ex) {
            throw new IllegalArgumentException("Failed to serialize object of type: " + object.getClass(), ex);
        }
        return baos.toByteArray();
    }
}

Related

  1. serialize(Object object)
  2. serialize(Object object)
  3. serialize(Object object)
  4. serialize(Object object)
  5. serialize(Object object)
  6. serialize(Object object)
  7. serialize(Object object, boolean zipped)
  8. serialize(Object object, File file)
  9. serialize(Object object, File file)