diff --git a/hutool-json/pom.xml b/hutool-json/pom.xml index 01df0cdf3..e28c6ecd9 100755 --- a/hutool-json/pom.xml +++ b/hutool-json/pom.xml @@ -59,6 +59,11 @@ 2.0.40 test + + com.alibaba + fastjson + 2.0.32 + io.jsonwebtoken jjwt-impl diff --git a/hutool-json/src/test/java/org/dromara/hutool/json/IssueI7VM64Test.java b/hutool-json/src/test/java/org/dromara/hutool/json/IssueI7VM64Test.java new file mode 100644 index 000000000..cbd852724 --- /dev/null +++ b/hutool-json/src/test/java/org/dromara/hutool/json/IssueI7VM64Test.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023. looly(loolly@aliyun.com) + * Hutool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * https://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +package org.dromara.hutool.json; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.HashMap; + +public class IssueI7VM64Test { + + @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") + @Test + void hutoolJSONTest() { + final HashMap map = new HashMap<>(); + map.put("a", "1"); + + final JSONObject jsonObject = new JSONObject(map); + map.put("b", 2); + + //Console.log("Hutool JSON: " + jsonObject); + Assertions.assertEquals("{\"a\":\"1\"}", jsonObject.toString()); + } + + @Test + void fastJSONTest() { + final HashMap map = new HashMap<>(); + map.put("a", "1"); + + final com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject(map); + map.put("b", 2); + + //Console.log("FastJSON: " + jsonObject); + Assertions.assertEquals("{\"a\":\"1\",\"b\":2}", jsonObject.toString()); + } + + @Test + void fastJSON2Test() { + final HashMap map = new HashMap<>(); + map.put("a", "1"); + + final com.alibaba.fastjson2.JSONObject jsonObject = new com.alibaba.fastjson2.JSONObject(map); + map.put("b", 2); + + //Console.log("FastJSON2 " + jsonObject); + Assertions.assertEquals("{\"a\":\"1\"}", jsonObject.toString()); + } +}