Class DeserializingObject<T,S extends SerializedObject<T>>
java.lang.Object
io.fluxcapacitor.javaclient.common.serialization.DeserializingObject<T,S>
- Type Parameters:
T
- The raw data type of the serialized object (e.g., String or byte[])S
- The specificSerializedObject
type used to represent the serialized payload
A wrapper around a
SerializedObject
that supports lazy deserialization of its payload.
This class defers the deserialization of the underlying object until it is first accessed via getPayload()
or getPayloadAs(Type)
. The result is then memoized to avoid repeated deserialization.
This is typically used for messages that may not require full deserialization (e.g. for routing or filtering). It is
extended by DeserializingMessage
which adds additional context and metadata.
-
Constructor Summary
ConstructorsConstructorDescriptionDeserializingObject
(S serializedObject, Function<Type, Object> payload) Creates a newDeserializingObject
with the given serialized representation and deserializer function. -
Method Summary
Modifier and TypeMethodDescriptionprotected MemoizingFunction
<Type, Object> Returns the memoized deserialization function used to deserialize the payload.<V> V
Returns the deserialized payload using the default target type (Object.class
).<V> V
getPayloadAs
(Type type) Returns the deserialized payload using the specified targetType
.Class
<?> Attempts to resolve the declared payload class usingReflectionUtils.classForName(String)
and throws an exception if the class cannot be found.int
Returns the revision number of the serialized payload, if available.getType()
Returns the declared type of the payload (e.g., fully qualified class name), ornull
if unknown.boolean
Returnstrue
if the payload has already been deserialized using the default type.
-
Constructor Details
-
DeserializingObject
Creates a newDeserializingObject
with the given serialized representation and deserializer function.- Parameters:
serializedObject
- The raw serialized objectpayload
- A function to deserialize the object when needed
-
-
Method Details
-
getObjectFunction
Returns the memoized deserialization function used to deserialize the payload. This method is protected for use in subclasses. -
getPayload
public <V> V getPayload()Returns the deserialized payload using the default target type (Object.class
). The result is cached and reused on subsequent calls. -
getPayloadAs
Returns the deserialized payload using the specified targetType
. Results are cached per type.- Type Parameters:
V
- the expected type of the deserialized object- Parameters:
type
- the desired target type
-
isDeserialized
public boolean isDeserialized()Returnstrue
if the payload has already been deserialized using the default type. -
getType
Returns the declared type of the payload (e.g., fully qualified class name), ornull
if unknown. -
getRevision
public int getRevision()Returns the revision number of the serialized payload, if available. -
getPayloadClass
Attempts to resolve the declared payload class usingReflectionUtils.classForName(String)
and throws an exception if the class cannot be found.- Returns:
- the
Class
corresponding to the declared type, ornull
if not resolvable
-