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 https://github.com/spring-projects/spring-framework/commit/ae5dd54115bd9e21917a66255a60f03d50d935f0 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

  • 14200

Comment From: snicoll

@sbrannen FTR, there was a PR reported against this that I've closed as you were already assigned. In case you haven't started anything and the PR addresses the issue, we can reconsider.