src/main/java/org/mvel2/conversion/ArrayHandler.java
private static Object handleLooseTypeConversion(Class sourceType, Object input, Class targetType) {
    Class targType = targetType.getComponentType();
    if (Collection.class.isAssignableFrom(sourceType)) {
      Object newArray = newInstance(targType, ((Collection) input).size());

      int i = 0;
      for (Object o : ((Collection) input)) {
        Array.set(newArray, i++, convert(o, targType));
      }

      return newArray;
    }

    if (!input.getClass().isArray()) {
      // if the input isn't an array converts it in an array with lenght = 1 having has its single item the input itself
      Object target = newInstance(targType, 1);
      set(target, 0, convert(input, targType));
      return target;
    }

    int len = getLength(input);
    Object target = newInstance(targType, len);

    for (int i = 0; i < len; i++) {
      set(target, i, convert(get(input, i), targType));
    }

    return target;
  }
/**
   * Messy method to handle primitive boxing for conversion. If someone can re-write this more
   * elegantly, be my guest.
   *
   * @param sourceType
   * @param input
   * @param targetType
   * @return
   */
Messy method to handle primitive boxing for conversion. If someone can re-write this more
elegantly, be my guest.


Messy method to handle primitive boxing for conversion . If someone can re - write this more elegantly be my guest .
private static Object handleLooseTypeConversion(Class sourceType, Object input, Class targetType) {
    Class targType = targetType.getComponentType();
    if (Collection.class.isAssignableFrom(sourceType)) {
      Object newArray = newInstance(targType, ((Collection) input).size());
      int i = 0;
      for (Object o : ((Collection) input)) {
        Array.set(newArray, i++, convert(o, targType));
      }
      return newArray;
    }
    if (!input.getClass().isArray()) {
      Object target = newInstance(targType, 1);
      set(target, 0, convert(input, targType));
      return target;
    }
    int len = getLength(input);
    Object target = newInstance(targType, len);
    for (int i = 0; i < len; i++) {
      set(target, i, convert(get(input, i), targType));
    }
    return target;
  }
private static Object handleLooseTypeConversion ( Class sourceType , Object input , Class targetType ) { Class targType = targetType . getComponentType ( ) ; if ( Collection . class . isAssignableFrom ( sourceType ) ) { Object newArray = newInstance ( targType , ( ( Collection ) input ) . size ( ) ) ; int i = 0 ; for ( Object o : ( ( Collection ) input ) ) { Array . set ( newArray , i ++ , convert ( o , targType ) ) ; } return newArray ; } if ( ! input . getClass ( ) . isArray ( ) ) { Object target = newInstance ( targType , 1 ) ; set ( target , 0 , convert ( input , targType ) ) ; return target ; } int len = getLength ( input ) ; Object target = newInstance ( targType , len ) ; for ( int i = 0 ; i < len ; i ++ ) { set ( target , i , convert ( get ( input , i ) , targType ) ) ; } return target ; }
Messy method to handle primitive boxing for conversion.
Messy method to handle primitive boxing for conversion .
// if the input isn't an array converts it in an array with lenght = 1 having has its single item the input itself