修复ignoreNullValue在JSONArray中无效问题

This commit is contained in:
Looly 2024-09-29 13:22:16 +08:00
parent 6d7d0abbba
commit be98b46349
4 changed files with 25 additions and 3 deletions

View File

@ -2,7 +2,7 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
# 5.8.33(2024-09-23)
# 5.8.33(2024-09-29)
### 🐣新特性
* 【core 】 SyncFinisher增加setExecutorService方法issue#IANKQ1@Gitee
@ -21,6 +21,7 @@
* 【http 】 修复重定向没有按照RFC7231规范跳转的问题修改为除了307外重定向使用GET方式issue#3722@Github
* 【core 】 修复ArrayUtil.lastIndexOfSub死循环问题issue#IAQ16E@Gitee
* 【core 】 修复ImgUtil.write写出临时文件未清理问题issue#IAPZG7@Gitee
* 【json 】 修复ignoreNullValue在JSONArray中无效问题issue#3759@Github
-------------------------------------------------------------------------------------------------------------
**# 5.8.32(2024-08-30)

View File

@ -594,6 +594,13 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
return false;
}
}
// issue#3759
final boolean ignoreNullValue = this.config.isIgnoreNullValue();
if (ObjectUtil.isNull(obj) && ignoreNullValue) {
return false;
}
return this.rawList.add(obj);
}
}

View File

@ -0,0 +1,14 @@
package cn.hutool.json;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class Issue3759Test {
@Test
void parseTest() {
String jsonArrayStr = "[null]";
final JSONArray objects = JSONUtil.parseArray(jsonArrayStr,
JSONConfig.create().setIgnoreNullValue(true));
Assertions.assertTrue(objects.isEmpty());
}
}

View File

@ -1,5 +1,5 @@
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
package cn.hutool.json;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;