修复ignoreNullValue在JSONArray中无效问题

This commit is contained in:
Looly
2024-11-05 20:04:57 +08:00
parent 735f531e3c
commit fe4e56fed7
2 changed files with 20 additions and 7 deletions

View File

@@ -167,7 +167,7 @@ public class JSONArrayTest {
@Test
public void toListWithNullTest() {
String json = "[null,{'akey':'avalue','bkey':'bvalue'}]";
JSONArray ja = JSONUtil.parseArray(json);
JSONArray ja = JSONUtil.parseArray(json, JSONConfig.create().setIgnoreNullValue(false));
List<KeyBean> list = ja.toList(KeyBean.class);
assertNull(list.get(0));
@@ -221,10 +221,15 @@ public class JSONArrayTest {
@Test
public void putToIndexTest() {
final JSONArray jsonArray = new JSONArray();
JSONArray jsonArray = new JSONArray(JSONConfig.create().setIgnoreNullValue(false));
jsonArray.put(3, "test");
// 第三个位置插入值0~2都是null
assertEquals(4, jsonArray.size());
jsonArray = new JSONArray(JSONConfig.create().setIgnoreNullValue(true));
jsonArray.put(3, "test");
// 第三个位置插入值忽略null则追加
assertEquals(1, jsonArray.size());
}
// https://github.com/dromara/hutool/issues/1858