Class TypeToken<T>

java.lang.Object
software.amazon.lambda.durable.TypeToken<T>
Type Parameters:
T - the type being captured

public abstract class TypeToken<T> extends Object
Framework-agnostic type token for capturing generic type information at runtime.

This class enables type-safe deserialization of complex generic types like List<MyObject> or Map<String, MyObject> that would otherwise lose their type information due to Java's type erasure.

Usage example:


 // Capture generic type information
 TypeToken<List<String>> token = new TypeToken<List<String>>() {};

 // Use with DurableContext
 List<String> items = context.step("fetch-items",
     new TypeToken<List<String>>() {},
     stepCtx -> fetchItems());
 
  • Constructor Details

    • TypeToken

      protected TypeToken()
      Constructs a new TypeToken. This constructor must be called from an anonymous subclass to capture the type parameter.
      Throws:
      IllegalStateException - if created without a type parameter
  • Method Details

    • get

      public static <U> TypeToken<U> get(Class<U> clazz)
    • getType

      public Type getType()
      Returns the captured type.
      Returns:
      the type represented by this token
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object