public final class InstantiationUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
InstantiationUtil.ClassLoaderObjectInputStream
A custom ObjectInputStream that can load classes using a specific ClassLoader.
|
| Modifier and Type | Method and Description |
|---|---|
static <T extends Serializable> |
clone(T obj)
Clones the given serializable object using Java serialization.
|
static <T extends Serializable> |
clone(T obj,
ClassLoader classLoader)
Clones the given serializable object using Java serialization, using the given classloader to
resolve the cloned classes.
|
static <T> T |
deserializeObject(byte[] bytes,
ClassLoader cl) |
static <T> T |
deserializeObject(InputStream in,
ClassLoader cl) |
static byte[] |
serializeObject(Object o) |
static void |
serializeObject(OutputStream out,
Object o) |
public static <T> T deserializeObject(byte[] bytes,
ClassLoader cl)
throws IOException,
ClassNotFoundException
IOExceptionClassNotFoundExceptionpublic static <T> T deserializeObject(InputStream in, ClassLoader cl) throws IOException, ClassNotFoundException
IOExceptionClassNotFoundExceptionpublic static byte[] serializeObject(Object o) throws IOException
IOExceptionpublic static void serializeObject(OutputStream out, Object o) throws IOException
IOExceptionpublic static <T extends Serializable> T clone(T obj) throws IOException, ClassNotFoundException
T - Type of the object to cloneobj - Object to cloneIOException - Thrown if the serialization or deserialization process fails.ClassNotFoundException - Thrown if any of the classes referenced by the object cannot
be resolved during deserialization.public static <T extends Serializable> T clone(T obj, ClassLoader classLoader) throws IOException, ClassNotFoundException
T - Type of the object to cloneobj - Object to cloneclassLoader - The classloader to resolve the classes during deserialization.IOException - Thrown if the serialization or deserialization process fails.ClassNotFoundException - Thrown if any of the classes referenced by the object cannot
be resolved during deserialization.Copyright © 2023–2025 The Apache Software Foundation. All rights reserved.