mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix test
This commit is contained in:
parent
7f4be2b639
commit
0ea87a38e6
@ -17,19 +17,24 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FastJSON和Hutool不同策略测试<br>
|
||||||
|
* 在put时,Hutool采用“即时转换”的方式,不再与原对象有关联,<br>
|
||||||
|
* 而FastJSON采用“暂存”方式,put进JSONObject的对象不变,只有序列化时转换
|
||||||
|
*/
|
||||||
public class IssueI7VM64Test {
|
public class IssueI7VM64Test {
|
||||||
|
|
||||||
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
|
|
||||||
@Test
|
@Test
|
||||||
void hutoolJSONTest() {
|
void hutoolJSONTest() {
|
||||||
final HashMap<String, Object> map = new HashMap<>();
|
final HashMap<String, Object> map = new HashMap<>();
|
||||||
map.put("a", "1");
|
map.put("a", "1");
|
||||||
|
|
||||||
final JSONObject jsonObject = new JSONObject(map);
|
final JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("c", map);
|
||||||
map.put("b", 2);
|
map.put("b", 2);
|
||||||
|
|
||||||
//Console.log("Hutool JSON: " + jsonObject);
|
//Console.log("Hutool JSON: " + jsonObject);
|
||||||
Assertions.assertEquals("{\"a\":\"1\"}", jsonObject.toString());
|
Assertions.assertEquals("{\"c\":{\"a\":\"1\"}}", jsonObject.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -37,11 +42,13 @@ public class IssueI7VM64Test {
|
|||||||
final HashMap<String, Object> map = new HashMap<>();
|
final HashMap<String, Object> map = new HashMap<>();
|
||||||
map.put("a", "1");
|
map.put("a", "1");
|
||||||
|
|
||||||
final com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject(map);
|
final com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
|
||||||
|
jsonObject.put("c", map);
|
||||||
|
|
||||||
map.put("b", 2);
|
map.put("b", 2);
|
||||||
|
|
||||||
//Console.log("FastJSON: " + jsonObject);
|
//Console.log("FastJSON: " + jsonObject);
|
||||||
Assertions.assertEquals("{\"a\":\"1\",\"b\":2}", jsonObject.toString());
|
Assertions.assertEquals("{\"c\":{\"a\":\"1\",\"b\":2}}", jsonObject.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -49,10 +56,12 @@ public class IssueI7VM64Test {
|
|||||||
final HashMap<String, Object> map = new HashMap<>();
|
final HashMap<String, Object> map = new HashMap<>();
|
||||||
map.put("a", "1");
|
map.put("a", "1");
|
||||||
|
|
||||||
final com.alibaba.fastjson2.JSONObject jsonObject = new com.alibaba.fastjson2.JSONObject(map);
|
final com.alibaba.fastjson2.JSONObject jsonObject = new com.alibaba.fastjson2.JSONObject();
|
||||||
|
jsonObject.put("c", map);
|
||||||
|
|
||||||
map.put("b", 2);
|
map.put("b", 2);
|
||||||
|
|
||||||
//Console.log("FastJSON2 " + jsonObject);
|
//Console.log("FastJSON2 " + jsonObject);
|
||||||
Assertions.assertEquals("{\"a\":\"1\"}", jsonObject.toString());
|
Assertions.assertEquals("{\"c\":{\"a\":\"1\",\"b\":2}}", jsonObject.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user