Java Is Serializable Object isSerializableType(Class type)

Here you can find the source of isSerializableType(Class type)

Description

Checks if is serializable type.

License

Open Source License

Parameter

Parameter Description
type the type

Return

true, if is serializable type

Declaration

public static boolean isSerializableType(Class<?> type) 

Method Source Code


//package com.java2s;
import java.io.Serializable;

public class Main {
    /**//from  www.j a  va  2  s .  c o m
     * Checks if is serializable type.
     *
     * @param type the type
     * @return true, if is serializable type
     */
    public static boolean isSerializableType(Class<?> type) {

        if (Void.class.isAssignableFrom(type)) {
            return true;
        }

        if (Object.class.isAssignableFrom(type) && !Serializable.class.isAssignableFrom(type)) {
            return false;
        }

        return true;
    }

    /**
     * Checks if is serializable type.
     *
     * @param types the types
     * @return true, if is serializable type
     */
    public static boolean isSerializableType(Class<?>... types) {

        if (null == types || types.length == 0) {
            return true;
        }

        for (Class<?> type : types) {
            if (!isSerializableType(type)) {
                return false;
            }
        }

        return true;
    }
}

Related

  1. isSerializable(Object o)
  2. isSerializable(Object ob)
  3. isSerializable(Object obj)
  4. isSerializable(Object obj)
  5. isSerializable(Object object)