Java Is Serializable Object isSerializable(Object o)

Here you can find the source of isSerializable(Object o)

Description

is Serializable

License

Apache License

Declaration

public static boolean isSerializable(Object o) throws IOException 

Method Source Code

//package com.java2s;
/*//from ww  w.j av a 2  s .  c o m
 * The Spring Framework is published under the terms
 * of the Apache Software License.
 */

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

import java.io.ObjectOutputStream;
import java.io.OutputStream;

public class Main {
    public static boolean isSerializable(Object o) throws IOException {
        try {
            testSerialization(o);
            return true;
        } catch (NotSerializableException ex) {
            return false;
        }
    }

    public static void testSerialization(Object o) throws IOException {
        OutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(o);
    }
}

Related

  1. isSerializable(Class c)
  2. isSerializable(Class clazz)
  3. isSerializable(Class clazz)
  4. isSerializable(final Object c)
  5. isSerializable(Object o)
  6. isSerializable(Object o)
  7. isSerializable(Object o)
  8. isSerializable(Object ob)