Merge branch '6.2.x'
This commit is contained in:
commit
49bd8333e8
|
|
@ -893,16 +893,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
private Object newValue(Class<?> type, @Nullable TypeDescriptor desc, String name) {
|
||||
try {
|
||||
if (type.isArray()) {
|
||||
Class<?> componentType = type.componentType();
|
||||
// TODO - only handles 2-dimensional arrays
|
||||
if (componentType.isArray()) {
|
||||
Object array = Array.newInstance(componentType, 1);
|
||||
Array.set(array, 0, Array.newInstance(componentType.componentType(), 0));
|
||||
return array;
|
||||
}
|
||||
else {
|
||||
return Array.newInstance(componentType, 0);
|
||||
}
|
||||
return createArray(type);
|
||||
}
|
||||
else if (Collection.class.isAssignableFrom(type)) {
|
||||
TypeDescriptor elementDesc = (desc != null ? desc.getElementTypeDescriptor() : null);
|
||||
|
|
@ -926,6 +917,24 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the array for the given array type.
|
||||
* @param arrayType the desired type of the target array
|
||||
* @return a new array instance
|
||||
*/
|
||||
private static Object createArray(Class<?> arrayType) {
|
||||
Assert.notNull(arrayType, "Array type must not be null");
|
||||
Class<?> componentType = arrayType.componentType();
|
||||
if (componentType.isArray()) {
|
||||
Object array = Array.newInstance(componentType, 1);
|
||||
Array.set(array, 0, createArray(componentType));
|
||||
return array;
|
||||
}
|
||||
else {
|
||||
return Array.newInstance(componentType, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given property name into the corresponding property name tokens.
|
||||
* @param propertyName the property name to parse
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -103,6 +103,27 @@ class BeanWrapperAutoGrowingTests {
|
|||
assertThat(bean.getThreeDimensionalArray()[1][2][3]).isInstanceOf(Bean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPropertyValueAutoGrow3dArrayList() {
|
||||
assertThat(wrapper.getPropertyValue("threeDimensionalArrayList[1][2][3][4]")).isNotNull();
|
||||
assertThat(bean.getThreeDimensionalArrayList()).hasSize(2);
|
||||
assertThat(bean.getThreeDimensionalArrayList().get(1)).hasNumberOfRows(3);
|
||||
assertThat(bean.getThreeDimensionalArrayList().get(1)[2]).hasNumberOfRows(4);
|
||||
assertThat(bean.getThreeDimensionalArrayList().get(1)[2][3]).hasSize(5);
|
||||
assertThat(bean.getThreeDimensionalArrayList().get(1)[2][3][4]).isInstanceOf(Bean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPropertyValueAutoGrow3dArrayListForDefault3dArray() {
|
||||
assertThat(wrapper.getPropertyValue("threeDimensionalArrayList[0]")).isNotNull();
|
||||
assertThat(bean.getThreeDimensionalArrayList()).hasSize(1);
|
||||
|
||||
// Default 3-dimensional array should be [[[]]]
|
||||
assertThat(bean.getThreeDimensionalArrayList().get(0)).hasNumberOfRows(1);
|
||||
assertThat(bean.getThreeDimensionalArrayList().get(0)[0]).hasNumberOfRows(1);
|
||||
assertThat(bean.getThreeDimensionalArrayList().get(0)[0][0]).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void setPropertyValueAutoGrow2dArray() {
|
||||
Bean newBean = new Bean();
|
||||
|
|
@ -123,6 +144,16 @@ class BeanWrapperAutoGrowingTests {
|
|||
.extracting(Bean::getProp).isEqualTo("enigma");
|
||||
}
|
||||
|
||||
@Test
|
||||
void setPropertyValueAutoGrow3dArrayList() {
|
||||
Bean newBean = new Bean();
|
||||
newBean.setProp("enigma");
|
||||
wrapper.setPropertyValue("threeDimensionalArrayList[0][1][2][3]", newBean);
|
||||
assertThat(bean.getThreeDimensionalArrayList().get(0)[1][2][3])
|
||||
.isInstanceOf(Bean.class)
|
||||
.extracting(Bean::getProp).isEqualTo("enigma");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPropertyValueAutoGrowList() {
|
||||
assertThat(wrapper.getPropertyValue("list[0]")).isNotNull();
|
||||
|
|
@ -215,6 +246,8 @@ class BeanWrapperAutoGrowingTests {
|
|||
|
||||
private Bean[][][] threeDimensionalArray;
|
||||
|
||||
private List<Bean[][][]> threeDimensionalArrayList;
|
||||
|
||||
private List<Bean> list;
|
||||
|
||||
private List<List<Bean>> nestedList;
|
||||
|
|
@ -269,6 +302,14 @@ class BeanWrapperAutoGrowingTests {
|
|||
this.threeDimensionalArray = threeDimensionalArray;
|
||||
}
|
||||
|
||||
public List<Bean[][][]> getThreeDimensionalArrayList() {
|
||||
return threeDimensionalArrayList;
|
||||
}
|
||||
|
||||
public void setThreeDimensionalArrayList(List<Bean[][][]> threeDimensionalArrayList) {
|
||||
this.threeDimensionalArrayList = threeDimensionalArrayList;
|
||||
}
|
||||
|
||||
public List<Bean> getList() {
|
||||
return list;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue