修复props.toBean 数组字段未赋值问题

This commit is contained in:
Looly
2023-03-26 05:53:45 +08:00
parent 8bd76de6fe
commit 5799e018c1
9 changed files with 106 additions and 62 deletions

View File

@@ -2,6 +2,8 @@ package cn.hutool.core.bean;
import cn.hutool.core.lang.test.bean.ExamInfoDict;
import cn.hutool.core.lang.test.bean.UserInfoDict;
import cn.hutool.core.util.ArrayUtil;
import lombok.Data;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -124,4 +126,20 @@ public class BeanPathTest {
beanPath.set(map, "张三");
Assert.assertEquals("{list=[[null, {name=张三}]]}", map.toString());
}
@Test
public void appendArrayTest(){
// issue#3008@Github
final MyUser myUser = new MyUser();
BeanPath.create("hobby[0]").set(myUser, "LOL");
BeanPath.create("hobby[1]").set(myUser, "KFC");
BeanPath.create("hobby[2]").set(myUser, "COFFE");
Assert.assertEquals("[LOL, KFC, COFFE]", ArrayUtil.toString(myUser.getHobby()));
}
@Data
static class MyUser {
private String[] hobby;
}
}