Class Converters

java.lang.Object
io.leandev.appfuse.converter.Converters

public class Converters extends Object

型別轉換器註冊表

管理和查詢各種型別轉換器的中央註冊表。 預設註冊了常用的基本型別轉換器。

  • Constructor Details

    • Converters

      public Converters()
      建立轉換器註冊表並註冊預設轉換器
  • Method Details

    • register

      public <T> void register(Class<T> targetType, Converter<T> converter)
      Registers a converter for a specific target type.
      Type Parameters:
      T - the target type
      Parameters:
      targetType - the class of the target type
      converter - the converter instance
    • lookup

      public <T> Converter<T> lookup(Class<T> targetType)
      Looks up a converter for the given target type.
      Type Parameters:
      T - The target type.
      Parameters:
      targetType - The class of the target type.
      Returns:
      The found converter, or null if no converter is registered for the type.
    • convert

      public <T> T convert(Object value, Class<T> targetType)
      Converts a value to the specified target type.
      Type Parameters:
      T - the target type
      Parameters:
      value - the value to convert
      targetType - the class of the target type
      Returns:
      the converted value
      Throws:
      ConversionException - if no converter is found or conversion fails