Class ConfigurableConverter

All Implemented Interfaces:
Converter

A BasicConverter subclass that supports pluggable type conversion discovery via ConversionFinder.

Pass one or more ConversionFinder instances to the constructor. Finders are consulted in order before falling back to the built-in BasicConverter reflection logic.

Example:

ConfigurableConverter converter = new ConfigurableConverter( (in, out) -> in == String.class && out == MyBean.class ? (s, memberOf, session, args) -> MyBean.fromString((String) s) : null ); MyBean bean = converter.to("value", MyBean.class);

See Also:
  • Constructor Details

  • Method Details

    • hasCustomConversion

      public boolean hasCustomConversion(Class<?> inType, Class<?> outType)
      Returns true if any registered ConversionFinder can convert the specified type pair.

      This only checks the registered finders, not the built-in BasicConverter reflection logic.

      Parameters:
      inType - The input type class.
      outType - The output type class.
      Returns:
      true if a finder-provided conversion exists for the specified type pair.
    • findConversion

      protected <I, O> Conversion<I,O> findConversion(Class<I> inType, Class<O> outType)
      Description copied from class: CachingConverter
      Finds a conversion function from the specified input type to the specified output type.

      This method is called lazily the first time a conversion between a given type pair is requested. The result is cached so subsequent calls for the same type pair bypass this method entirely. When this method returns null, a sentinel is stored so that unconvertable type pairs are also only evaluated once.

      Implementations should return null if no conversion is possible for the given types, which will cause CachingConverter.to(Object, Class) and CachingConverter.to(Object, Type, Type...) to throw InvalidConversionException for that type pair.

      Overrides:
      findConversion in class BasicConverter
      Type Parameters:
      I - The input type.
      O - The output type.
      Parameters:
      inType - The runtime class of the input object.
      outType - The target output class.
      Returns:
      A Conversion function, or null if no conversion is available.