Class TypeCoercionUtil

java.lang.Object
io.github.connellite.util.TypeCoercionUtil

public class TypeCoercionUtil extends Object
Default value coercion for bean and map mapping.

Converts a runtime value toward a target Java type. This is the fallback used by SimpleResultSetBeanMapper and SimpleMapBeanMapper when no custom converter is configured.

null input always yields null. For many target types an incompatible value also yields null instead of throwing. Parsing failures and unsupported target types throw TypeCoercionException.

Supported targets include:

JDBC date/time targets also accept java.time values, Calendar, epoch Number, and all-digit epoch-millis strings. Other strings delegate to DateTimeUtil (LocalDate, LocalTime, LocalDateTime formats).

A primitive array and the array of its wrapper are copied through NumberUtils. Any other array is converted element by element. null elements stay null in a wrapper array. A null element stored into a primitive array throws TypeCoercionException. Blob still converts to byte[]. A String converts to byte[]/Byte[] as UTF-8 and to char[]/Character[] as its characters. The reverse uses new String: chars as written, bytes and Blob decoded as UTF-8. char[]/Character[] become a Clob the same way a string does. Byte[] is accepted wherever byte[] is: Blob and UUID.

  • Constructor Details

    • TypeCoercionUtil

      public TypeCoercionUtil()
  • Method Details

    • coerce

      public static <T> T coerce(Object raw, Class<T> targetType)
      Coerces raw toward targetType.
      Type Parameters:
      T - target type
      Parameters:
      raw - source value; null yields null
      targetType - desired type, including primitives
      Returns:
      coerced value compatible with targetType, or null
      Throws:
      TypeCoercionException - when coercion fails definitively