Type Parameters:
I - the input type before casting
O - the output type after casting
All Known Subinterfaces:
CasterChain<I,O>
All Known Implementing Classes:
DefaultCasterChain
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Caster<I,O>
Functional interface representing a transformation from one stream of values to another, possibly adjusting for version compatibility or format changes.

This interface is typically used to implement:

  • Upcasting: Transforming older versions of serialized data to newer schema versions.
  • Downcasting: Reducing an object’s structure to an earlier schema version.

The cast(Stream, Integer) method may inspect the desired revision and apply transformation logic accordingly.

Casters are often discovered and applied as part of a CasterChain, which enables chaining and runtime composition of multiple casting transformations.

  • Method Summary

    Modifier and Type
    Method
    Description
    default Stream<? extends O>
    cast(Stream<? extends I> input)
    Casts the given stream of input values to the output format using the default transformation rules.
    Stream<? extends O>
    cast(Stream<? extends I> input, Integer desiredRevision)
    Casts the given stream of input values to the output format, optionally considering a target revision.
    default <BEFORE, AFTER>
    Caster<BEFORE,AFTER>
    intercept(Function<BEFORE,? extends I> before, Function<? super O,AFTER> after)
    Creates a new Caster that applies preprocessing and postprocessing steps before and after the core cast.
  • Method Details

    • cast

      default Stream<? extends O> cast(Stream<? extends I> input)
      Casts the given stream of input values to the output format using the default transformation rules. This is equivalent to calling cast(input, null).
      Parameters:
      input - the input stream of values
      Returns:
      a stream of transformed output values
    • cast

      Stream<? extends O> cast(Stream<? extends I> input, Integer desiredRevision)
      Casts the given stream of input values to the output format, optionally considering a target revision.
      Parameters:
      input - the input stream of values
      desiredRevision - the target revision number (nullable)
      Returns:
      a stream of transformed output values
    • intercept

      default <BEFORE, AFTER> Caster<BEFORE,AFTER> intercept(Function<BEFORE,? extends I> before, Function<? super O,AFTER> after)
      Creates a new Caster that applies preprocessing and postprocessing steps before and after the core cast.
      Type Parameters:
      BEFORE - the new input type
      AFTER - the new output type
      Parameters:
      before - a function to transform input from type BEFORE to I
      after - a function to transform output from O to AFTER
      Returns:
      a composed Caster with adapted input/output types