mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -34,9 +34,7 @@ public class Issue2746Test {
|
||||
|
||||
@Test
|
||||
public void parseTest() {
|
||||
Assertions.assertThrows(JSONException.class, ()->{
|
||||
final String str = StrUtil.repeat("[", 1500) + StrUtil.repeat("]", 1500);
|
||||
JSONUtil.parseArray(str);
|
||||
});
|
||||
final String str = StrUtil.repeat("[", 1500) + StrUtil.repeat("]", 1500);
|
||||
JSONUtil.parseArray(str);
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,10 @@ import org.dromara.hutool.json.test.bean.KeyBean;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -315,11 +318,12 @@ public class JSONArrayTest {
|
||||
final String jsonArr = "[{\"id\":111,\"name\":\"test1\"},{\"id\":112,\"name\":\"test2\"}]";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONArray array = new JSONArray(jsonArr, null, (mutable) -> {
|
||||
final JSONObject o = new JSONObject(mutable.get());
|
||||
if ("111".equals(o.getStr("id"))) {
|
||||
o.set("name", "test1_edit");
|
||||
if(mutable.getKey() instanceof Integer){
|
||||
final JSONObject o = (JSONObject) mutable.getValue();
|
||||
if ("111".equals(o.getStr("id"))) {
|
||||
o.set("name", "test1_edit");
|
||||
}
|
||||
}
|
||||
mutable.set(new AbstractMap.SimpleEntry<>(1, o));
|
||||
return true;
|
||||
});
|
||||
assertEquals(2, array.size());
|
||||
|
@@ -16,27 +16,21 @@
|
||||
|
||||
package org.dromara.hutool.json;
|
||||
|
||||
import lombok.Data;
|
||||
import org.dromara.hutool.core.annotation.Alias;
|
||||
import org.dromara.hutool.core.annotation.PropIgnore;
|
||||
import org.dromara.hutool.core.collection.ListUtil;
|
||||
import org.dromara.hutool.core.date.DatePattern;
|
||||
import org.dromara.hutool.core.date.DateUtil;
|
||||
import org.dromara.hutool.core.io.resource.ResourceUtil;
|
||||
import org.dromara.hutool.core.lang.Console;
|
||||
import org.dromara.hutool.core.map.MapUtil;
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.core.util.ObjUtil;
|
||||
import org.dromara.hutool.json.test.bean.JSONBean;
|
||||
import org.dromara.hutool.json.test.bean.ResultDto;
|
||||
import org.dromara.hutool.json.test.bean.Seq;
|
||||
import org.dromara.hutool.json.test.bean.TokenAuthResponse;
|
||||
import org.dromara.hutool.json.test.bean.TokenAuthWarp2;
|
||||
import org.dromara.hutool.json.test.bean.UserA;
|
||||
import org.dromara.hutool.json.test.bean.UserB;
|
||||
import org.dromara.hutool.json.test.bean.UserWithMap;
|
||||
import org.dromara.hutool.json.test.bean.*;
|
||||
import org.dromara.hutool.json.test.bean.report.CaseReport;
|
||||
import org.dromara.hutool.json.test.bean.report.StepReport;
|
||||
import org.dromara.hutool.json.test.bean.report.SuiteReport;
|
||||
import lombok.Data;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -45,12 +39,7 @@ import java.io.StringReader;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* JSONObject单元测试
|
||||
@@ -195,7 +184,7 @@ public class JSONObjectTest {
|
||||
final String jsonStr = "{\"a\":\"<div>aaa</div>\"}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONObject json = new JSONObject(jsonStr);
|
||||
Assertions.assertEquals("<div>aaa</div>", json.get("a"));
|
||||
Assertions.assertEquals("<div>aaa</div>", json.getObj("a"));
|
||||
Assertions.assertEquals(jsonStr, json.toString());
|
||||
}
|
||||
|
||||
@@ -752,7 +741,8 @@ public class JSONObjectTest {
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONObject jsonObject = new JSONObject(jsonStr, null, (pair)-> {
|
||||
if("b".equals(pair.getKey())){
|
||||
pair.setValue(pair.getValue() + "_edit");
|
||||
final JSONPrimitive primitive = (JSONPrimitive) pair.getValue();
|
||||
pair.setValue(primitive.getValue() + "_edit");
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
@@ -16,10 +16,10 @@
|
||||
|
||||
package org.dromara.hutool.json.writer;
|
||||
|
||||
import lombok.Data;
|
||||
import org.dromara.hutool.core.convert.Converter;
|
||||
import org.dromara.hutool.json.JSONConfig;
|
||||
import org.dromara.hutool.json.JSONUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
Reference in New Issue
Block a user