修复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

@@ -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;