Overview
The DefaultConversionService currently cannot convert a primitive array to Object[]. This is due to the use of GenericConversionService.canBypassConvert(...) in ArrayToArrayConverter which assumes a conversion from int[] (or any other primitive array) to Object[] is unnecessary because "an int (or other primitive type) can be converted to an Object by returning the source object unchanged," although the latter is not true for primitives.
Thus an attempt to convert from int[] to Object[] returns the source int[] array unchanged and incompatible with Object[].
This strikes me as a bit strange since the following conversions (and other similar conversions) are all supported. See the various convert*() test methods in DefaultConversionServiceTests.
int[] --> Integer[]
int[] --> String[]
int[] --> float[]
Object[] --> Integer[]
Object[] --> int[]
The latter makes it clear that you can convert from Object[] to int[] but not from int[] to Object[].
Note that this also affects our varargs support in SpEL expressions. See the various @Disabled tests in ae5dd54 for examples.
We should decide if we want to support conversions from primitive arrays to Object[] and otherwise consider documenting this as a known limitation.
Related Issues
Overview
The
DefaultConversionServicecurrently cannot convert a primitive array toObject[]. This is due to the use ofGenericConversionService.canBypassConvert(...)inArrayToArrayConverterwhich assumes a conversion fromint[](or any other primitive array) toObject[]is unnecessary because "anint(or other primitive type) can be converted to anObjectby returning the source object unchanged," although the latter is not true for primitives.Thus an attempt to convert from
int[]toObject[]returns the sourceint[]array unchanged and incompatible withObject[].This strikes me as a bit strange since the following conversions (and other similar conversions) are all supported. See the various
convert*()test methods inDefaultConversionServiceTests.int[]-->Integer[]int[]-->String[]int[]-->float[]Object[]-->Integer[]Object[]-->int[]The latter makes it clear that you can convert from
Object[]toint[]but not fromint[]toObject[].Note that this also affects our varargs support in SpEL expressions. See the various
@Disabledtests in ae5dd54 for examples.We should decide if we want to support conversions from primitive arrays to
Object[]and otherwise consider documenting this as a known limitation.Related Issues