This class throws exceptions for invalid null inputs.
Each method documents its behavior in more detail.
#ThreadSafe#
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | SerializationUtils.
Custom specialization of the standard JDK |
| Access | Constructor and Description |
|---|---|
| public | SerializationUtils()
Deprecated
TODO Make private in 4.0.
SerializationUtils instances should NOT be constructed in standard programming. |
| Modifier and Type | Method and Description |
|---|---|
| public static < the type of the object involved. T extends Serializable> T | Returns: the cloned object.the object)Serializable object to clone.Deep clones an |
| public static < the object type to be deserialized. T> T | Returns: the deserialized object.the serialized object, must not be null. objectData)Deserializes a single |
| public static < the object type to be deserialized. T> T | Returns: the deserialized object.the serialized object input stream, must not be null. inputStream)Deserializes an |
| public static < the type of the object involved. T extends Serializable> T | Returns: the serialized and deserialized object.the object to roundtrip. obj)Performs a serialization roundtrip. |
| public static byte[] | Returns: a byte[] with the converted Serializable.the object to serialize to bytes. obj)Serializes an |
| public static void | serialize(final Serializable
the object to serialize to bytes, may be null. obj, final OutputStream the stream to write to, must not be null. outputStream)Serializes an |
| SerializationUtils | back to summary |
|---|---|
| public SerializationUtils()
Deprecated TODO Make private in 4.0. SerializationUtils instances should NOT be constructed in standard programming.
Instead, the class should be used as This constructor is public to permit tools that require a JavaBean instance to operate.
| |
| clone | back to summary |
|---|---|
| public static <T extends Serializable> T clone(final T object) Deep clones an This is many times slower than writing clone methods by hand
on all objects in your object graph. However, for complex object
graphs, or for those that don't support deep cloning this can
be a simple alternative implementation. Of course all the objects
must be
| |
| deserialize | back to summary |
|---|---|
| public static <T> T deserialize(final byte[] objectData) Deserializes a single
If the call site incorrectly types the return value, a
| |
| deserialize | back to summary |
|---|---|
| public static <T> T deserialize(final InputStream inputStream) Deserializes an The stream will be closed once the object is written. This avoids the need for a finally clause, and maybe also exception handling, in the application code. The stream passed in is not buffered internally within this method. This is the responsibility of your application if desired.
If the call site incorrectly types the return value, a
| |
| roundtrip | back to summary |
|---|---|
| public static <T extends Serializable> T roundtrip(final T obj) Performs a serialization roundtrip. Serializes and deserializes the given object, great for testing objects that
implement
| |
| serialize | back to summary |
|---|---|
| public static byte[] serialize(final Serializable obj) Serializes an
| |
| serialize | back to summary |
|---|---|
| public static void serialize(final Serializable obj, final OutputStream outputStream) Serializes an The stream will be closed once the object is written. This avoids the need for a finally clause, and maybe also exception handling, in the application code. The stream passed in is not buffered internally within this method. This is the responsibility of your application if desired.
| |
ObjectInputStream
that uses a custom ClassLoader to resolve a class.
If the specified ClassLoader is not able to resolve the class,
the context classloader of the current thread will be used.
This way, the standard deserialization work also in web-application
containers and application servers, no matter in which of the
ClassLoader the particular class that encapsulates
serialization/deserialization lives.
For more in-depth information about the problem for which this class here is a workaround, see the JIRA issue LANG-626.
| Modifier and Type | Field and Description |
|---|---|
| private final ClassLoader |
| Access | Constructor and Description |
|---|---|
| pack-priv | ClassLoaderAwareObjectInputStream(final InputStream
The in, final ClassLoader InputStream.classloader to use classLoader)Constructs a new instance. |
| Modifier and Type | Method and Description |
|---|---|
| protected Class | resolveClass(final ObjectStreamClass
An instance of class desc)ObjectStreamClass.Overrides java. Overridden version that uses the parameterized |
| classLoader | back to summary |
|---|---|
| private final ClassLoader classLoader | |
| ClassLoaderAwareObjectInputStream | back to summary |
|---|---|
| pack-priv ClassLoaderAwareObjectInputStream(final InputStream in, final ClassLoader classLoader) throws IOException Constructs a new instance.
| |
| resolveClass | back to summary |
|---|---|
| protected Class Overrides java. Overridden version that uses the parameterized
| |