Skip to content

Commit f4604cf

Browse files
committed
Merge branch '6.1.x'
2 parents 776a1d4 + cb6a5ba commit f4604cf

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

spring-core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@
3434
*
3535
* @author Keith Donald
3636
* @author Phillip Webb
37+
* @author Sam Brannen
3738
* @since 3.0
3839
*/
3940
final class ArrayToArrayConverter implements ConditionalGenericConverter {
@@ -64,8 +65,8 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
6465
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
6566
if (this.conversionService instanceof GenericConversionService genericConversionService) {
6667
TypeDescriptor targetElement = targetType.getElementTypeDescriptor();
67-
if (targetElement != null && genericConversionService.canBypassConvert(
68-
sourceType.getElementTypeDescriptor(), targetElement)) {
68+
if (targetElement != null && targetType.getType().isInstance(source) &&
69+
genericConversionService.canBypassConvert(sourceType.getElementTypeDescriptor(), targetElement)) {
6970
return source;
7071
}
7172
}

spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.util.regex.Pattern;
4444
import java.util.stream.Stream;
4545

46-
import org.junit.jupiter.api.Disabled;
4746
import org.junit.jupiter.api.Test;
4847

4948
import org.springframework.core.MethodParameter;
@@ -640,8 +639,7 @@ void convertObjectArrayToIntArray() {
640639
assertThat(result).containsExactly(1, 2, 3);
641640
}
642641

643-
@Disabled("Primitive array to Object[] conversion is not currently supported")
644-
@Test
642+
@Test // gh-33212
645643
void convertIntArrayToObjectArray() {
646644
Object[] result = conversionService.convert(new int[] {1, 2}, Object[].class);
647645
assertThat(result).containsExactly(1, 2);

0 commit comments

Comments
 (0)