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 specific SerializedObject type used to represent the serialized payload

public class DeserializingObject<T,S extends SerializedObject<T>> extends Object
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 Details

    • DeserializingObject

      public DeserializingObject(S serializedObject, Function<Type,Object> payload)
      Creates a new DeserializingObject with the given serialized representation and deserializer function.
      Parameters:
      serializedObject - The raw serialized object
      payload - A function to deserialize the object when needed
  • Method Details

    • getObjectFunction

      protected MemoizingFunction<Type,Object> 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

      public <V> V getPayloadAs(Type type)
      Returns the deserialized payload using the specified target Type. 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()
      Returns true if the payload has already been deserialized using the default type.
    • getType

      public String getType()
      Returns the declared type of the payload (e.g., fully qualified class name), or null if unknown.
    • getRevision

      public int getRevision()
      Returns the revision number of the serialized payload, if available.
    • getPayloadClass

      public Class<?> getPayloadClass()
      Attempts to resolve the declared payload class using ReflectionUtils.classForName(String) and throws an exception if the class cannot be found.
      Returns:
      the Class corresponding to the declared type, or null if not resolvable