We try to convert an Object to an Array and this is not easy in Java so we need a little bit of nasty magic.

@param <T>   Type of elements
@param clazz Clazz of the Objct elements
@param obj   Object
@return Array
325146
@SuppressWarnings({"unchecked", "unused"})
    public static <T> T[] object2Array(final Class<T> clazz, final Object obj) {
        return (T[]) obj;
    }
580822
public static Object arrayToString(final Object obj) {
        if (obj != null && obj.getClass().isArray()) {
            final int len = Array.getLength(obj);
            final String[] strings = new String[len];
            for (int i = 0; i < len; i++) {
                strings[i] = String.valueOf(Array.get(obj, i));
            }
            return Arrays.toString(strings);
        } else {
            return obj;
        }
    }
1314644
public static Object toArray(Object list, Class<?> clazz) {
        if (list == null)
            return Array.newInstance(clazz, 0);

        if (list instanceof List) {
            List<?> l = (List<?>) list;
            if (clazz.isPrimitive()) {
                Object a = Array.newInstance(clazz, l.size());
                for (int i = 0; i < l.size(); i++)
                    Array.set(a, i, l.get(i));
                return a;
            }
            return l.toArray((Object[]) Array.newInstance(clazz, l.size()));

        }

        Object a = Array.newInstance(clazz, 1);
        Array.set(a, 0, list);
        return a;
    }
61994
public static <T, J extends Convertable<T>> T[] convertToArray(J[] array) {
        return toArray(convert(array));
    }
276598
public static Object[] toArray(Object obj)
	{
		if (obj instanceof Object[])
			return (Object[]) obj;
		else
		{
			Object[] returnArray =
			{ obj };
			return returnArray;

		}
	}
744600
public <T> T convert(Object object, Class<T> clazz) {
        if (object == null) {
            return null;
        }

        return mapper.convertValue(object, clazz);
    }
820584
public static function objectToArray($obj)
    {
        if (is_object($obj)) {
            if (method_exists($obj, 'toArray')) {
                $obj = $obj->toArray();
            } elseif (method_exists($obj, '__toArray')) {
                $obj = $obj->__toArray();
            } else {
                $obj = (array)$obj;
            }
        }
        if (is_array($obj)) {
            $new = [];
            foreach ($obj as $key => $val) {
                $new[$key] = self::objectToArray($val);
            }
        } else {
            $new = $obj;
        }

        return $new;
    }
1063159
@Override
  public Object[] array() {
    DataType dt = data.dataType();
    Object[] list = new Object[length];
    try {
      for (int i = 0; i < length; i++) {
        if (!data.isNullAt(offset + i)) {
          list[i] = get(i, dt);
        }
      }
      return list;
    } catch(Exception e) {
      throw new RuntimeException("Could not get the array", e);
    }
  }
726944
public static byte[] serialize(final Object obj) {
        if (obj == null) {
            return null;
        }
        try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
            final ObjectOutputStream out = new ObjectOutputStream(baos);
            out.writeObject(obj);
            return baos.toByteArray();
        } catch (final IOException ex) {
            throw new RuntimeException(ex);
        }
    }
260211
protected static <U> Class<U>[] asArray(Class<U> clazz) {
		@SuppressWarnings("unchecked")
		Class<U>[] array = new Class[] { clazz };
		return array;
	}
842384
@SneakyThrows
    public static <T> T deserialize(final InputStream inputStream, final Class<T> clazz) {
        try (val in = new ObjectInputStream(inputStream)) {
            val obj = in.readObject();

            if (!clazz.isAssignableFrom(obj.getClass())) {
                throw new ClassCastException("Result [" + obj
                    + " is of type " + obj.getClass()
                    + " when we were expecting " + clazz);
            }
            return (T) obj;
        }
    }
611258
public static byte[] toByteArray(Serializable obj) {
        byte[] bytes = null;
        ObjectOutputStream oos = null;
        ByteArrayOutputStream baos = null;
        try {
            baos = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(baos);
            oos.writeObject(obj);
            oos.flush();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            if (oos != null) {
                try {
                    oos.close();
                    bytes = baos.toByteArray();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        return bytes;
    }
805788
public boolean isArray(C clazz) {
        Class j = toJavaClass(clazz);
        return j.isArray() || List.class.isAssignableFrom(j);
    }
1235872
@SneakyThrows
    public static <T extends Collection> T toCollection(final Object obj, final Class<T> clazz) {
        val results = toCollection(obj);
        if (clazz.isInterface()) {
            throw new IllegalArgumentException("Cannot accept an interface " + clazz.getSimpleName() + " to create a new object instance");
        }
        val col = clazz.getDeclaredConstructor().newInstance();
        col.addAll(results);
        return col;
    }
893777
function makeArray(obj) {
        var isArray;
        if ((isArray = Array.isArray)) {
            return isArray(obj) ? obj : [obj];
        }
        return ArrayPrototype.concat(obj);
    }
1287292
public static <T, J extends Convertable<T>> T[] convertToArray(J[] array, Class<T> clazz) {
        return toArray(convert(array), clazz);
    }
469097
public static <T> T convertToObject(Class<T> clazz, InputStream inputStream) {
		return convertToObject(clazz, new InputStreamReader(inputStream));
	}