T - the type of the marshalled object.public final class Marshalled<T> extends Object
getObject() method and
byte array representation via getBytes() method.
Conversions from byte array to object and from object to byte array are performed lazily and
results of conversions are cached. The strategy the defines how the object is represented
in a byte array is specified by Marshaller. There is a built-in
serialization marshaller that uses Java Object Serialization.
It is used by default. See Marshaller class for more details.
null object is always represented by null byte array and vice versa.
Marshalled object is not serializable by itself, but IOUtil.objectToBytes(Object) and
IOUtil.writeObject(DataOutput, Object) methods understand this object and use the result of
getBytes() invocation when serialization marshaller is used.
getObject() or getObject(ClassLoader)
methods, unless it was explicitly specified during marshalled object creation via
forObject(Object) or forObject(Object, Marshaller) methods. The first invocation
of getObject defines what class loader is used. If object cannot be deserialized from the
corresponding byte array on the first getObject invocation, then all subsequent invocations of
any getObject method will throw the same MarshallingException.
| Modifier and Type | Field and Description |
|---|---|
static Marshalled<Object> |
NULL
The null object for default
SERIALIZATION marshaller. |
| Modifier and Type | Method and Description |
|---|---|
void |
ensureBytes()
Ensures that object is converted into byte representation.
|
boolean |
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
static Marshalled<Object> |
forBytes(byte[] bytes)
Returns marshalled object for a specified byte array assuming that
The result of this method is not
null. |
static <T> Marshalled<T> |
forBytes(byte[] bytes,
Marshaller<T> marshaller)
Returns marshalled object for a specified byte array and marshaller.
|
static <T> Marshalled<T> |
forBytes(byte[] bytes,
Marshaller<T> marshaller,
SerialClassContext serialContext)
Returns marshalled object for a specified byte array and marshaller.
|
static <T> Marshalled<T> |
forObject(T object)
Wraps object into marshalled with a
serialization marshaller. |
static <T> Marshalled<T> |
forObject(T object,
Marshaller<T> marshaller)
Wraps object into marshalled with a specified marshaller.
|
byte[] |
getBytes()
Returns byte array representation of this marshalled object.
|
Marshaller<T> |
getMarshaller()
Returns a strategy that defines how an object is represented in a byte array.
|
T |
getObject()
Returns object representation of this marshalled object.
|
T |
getObject(ClassLoader cl)
Deprecated.
use
getObject() |
int |
hashCode()
Returns a hash code value for the object that is composed of the hashcode of its
marshaller and bytes. |
String |
toString()
Returns a compact string representation of the
object represented by this marshalled object. |
static Object |
unwrap(Object object)
Unwraps
Marshalled argument via getObject() call or returns object unmodified. |
public static final Marshalled<Object> NULL
SERIALIZATION marshaller.
This object the the result of forObject(null)
invocation and of the forBytes(null) invocation.
Both getObject and getBytes methods on this
instance return null.public static Object unwrap(Object object)
Marshalled argument via getObject() call or returns object unmodified.public static <T> Marshalled<T> forObject(T object)
serialization marshaller.
The result of this method is not null. It returns NULL object
when the argument is null.T - the type of the object.object - the object.public static <T> Marshalled<T> forObject(T object, Marshaller<T> marshaller)
null.T - the type of the object.object - the object.marshaller - the marshaller.NullPointerException - if marshaller does not
support null object and object is null.public static Marshalled<Object> forBytes(byte[] bytes)
null. It returns NULL object
when the argument is null.
serialization marshaller was used to create the specified byte array.bytes - the byte array.public static <T> Marshalled<T> forBytes(byte[] bytes, Marshaller<T> marshaller)
null.bytes - the byte array.public static <T> Marshalled<T> forBytes(byte[] bytes, Marshaller<T> marshaller, SerialClassContext serialContext)
null.bytes - the byte array.serialContext - the serial class context for load class.public T getObject()
Thread.getContextClassLoader) or
using the same class loader that loaded classes for this com.devexperts.io package when
context class loader is not defined.
This is a shortcut for getObject(null).MarshallingException - if object cannot be deserialized from its byte arraypublic T getObject(ClassLoader cl)
getObject()cl - the ClassLoader that will be used to load classes;
null for context class loader.MarshallingException - if object cannot be deserialized from its byte arraypublic void ensureBytes()
MarshallingException - if object cannot be converted to byte representationpublic byte[] getBytes()
public Marshaller<T> getMarshaller()
public boolean equals(Object obj)
marshallers and bytes are equal.equals in class Objecttrue if this object is the same as the obj
argument; false otherwise.MarshallingException - if object cannot be serialized to byte arraypublic int hashCode()
marshaller and bytes.hashCode in class ObjectMarshallingException - if object cannot be serialized to byte arraypublic String toString()
object represented by this marshalled object.
This method is designed to be used in logs.
If object cannot be deserialized from its byte array or there is an exception in its toString method,
then it returns error message.toString in class ObjectLogUtil.deepToString(Object)Copyright © 2002–2025 Devexperts LLC. All rights reserved.