Interface Converter<S,T>

Type Parameters:
S - the source type
T - the target type
All Known Implementing Classes:
DeserializingConverter, SerializingConverter
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 Converter<S,T>
A converter converts a source object of type S to a target of type T.

Implementations of this interface are thread-safe and can be shared.

Implementations may additionally implement ConditionalConverter.

Since:
3.0
Author:
Keith Donald, Josh Cummings
  • Method Summary

    Modifier and Type
    Method
    Description
    default <U> Converter<S,U>
    andThen(Converter<? super T,? extends U> after)
    Construct a composed Converter that first applies this Converter to its input, and then applies the after Converter to the result.
    convert(S source)
    Convert the source object of type S to target type T.
  • Method Details

    • convert

      @Nullable T convert(S source)
      Convert the source object of type S to target type T.
      Parameters:
      source - the source object to convert, which must be an instance of S (never null)
      Returns:
      the converted object, which must be an instance of T (potentially null)
      Throws:
      IllegalArgumentException - if the source cannot be converted to the desired target type
    • andThen

      default <U> Converter<S,U> andThen(Converter<? super T,? extends U> after)
      Construct a composed Converter that first applies this Converter to its input, and then applies the after Converter to the result.
      Type Parameters:
      U - the type of output of both the after Converter and the composed Converter
      Parameters:
      after - the Converter to apply after this Converter is applied
      Returns:
      a composed Converter that first applies this Converter and then applies the after Converter
      Since:
      5.3