This commit is contained in:
Looly 2024-06-18 10:21:52 +08:00
parent 51c1588081
commit c5e1ba85f8

View File

@ -0,0 +1,26 @@
package cn.hutool.json;
import cn.hutool.core.lang.Console;
import org.junit.Assert;
import org.junit.Test;
public class Issue3619Test {
@Test
public void parseObjTest() {
String json = "{\"@timestamp\":\"2024-06-14T00:02:06.438Z\",\"@version\":\"1\",\"int_arr\":[-4]}";
JSONConfig jsonConfig = JSONConfig.create().setKeyComparator(String.CASE_INSENSITIVE_ORDER);
JSONObject jsonObject = JSONUtil.parseObj(json, jsonConfig);
final String jsonStr = jsonObject.toJSONString(0, pair -> {
final Object key = pair.getKey();
if(key instanceof String){
// 只有key为String时才检查并过滤其它类型的key如int类型的key跳过
return key.toString().equals("int_arr");
}else{
return true;
}
});
Assert.assertEquals("{\"int_arr\":[-4]}", jsonStr);
}
}