Class ArrayCoercion

java.lang.Object
io.github.connellite.util.internal.ArrayCoercion

public class ArrayCoercion extends Object
Array coercion used by TypeCoercionUtil.
  • Constructor Details

    • ArrayCoercion

      public ArrayCoercion()
  • Method Details

    • coerce

      public static <T> T coerce(Object raw, Class<T> targetType)
      Coerces raw toward the array type targetType. The same runtime class is returned as-is. A primitive array and the array of its wrapper are copied through NumberUtils. Any other array is converted element by element. A non-array source yields null, except a Blob when the target is byte[] and a String when the target is a byte or char array, primitive or boxed.
      Type Parameters:
      T - target type
      Parameters:
      raw - source value, never null
      targetType - array type to coerce toward
      Returns:
      coerced array, or null when raw cannot be stored in targetType
      Throws:
      TypeCoercionException - when an element cannot be stored in the target array