deprecated json isOrder

This commit is contained in:
Looly
2022-03-28 13:29:31 +08:00
parent 695ea8ae3b
commit f69d49593b
11 changed files with 81 additions and 68 deletions

View File

@@ -0,0 +1,38 @@
package cn.hutool.json;
import lombok.Data;
import org.junit.Assert;
import org.junit.Test;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
public class Issue2223Test {
@Test
public void toStrOrderTest() {
Map<String, Long> m1 = new LinkedHashMap<>();
for (long i = 0; i < 5; i++) {
m1.put("2022/" + i, i);
}
Assert.assertEquals("{\"2022/0\":0,\"2022/1\":1,\"2022/2\":2,\"2022/3\":3,\"2022/4\":4}", JSONUtil.toJsonStr(m1));
Map<String, Map<String, Long>> map1 = new HashMap<>();
map1.put("m1", m1);
Assert.assertEquals("{\"m1\":{\"2022/0\":0,\"2022/1\":1,\"2022/2\":2,\"2022/3\":3,\"2022/4\":4}}",
JSONUtil.toJsonStr(map1, JSONConfig.create()));
final BeanDemo beanDemo = new BeanDemo();
beanDemo.setMap1(map1);
Assert.assertEquals("{\"map1\":{\"m1\":{\"2022/0\":0,\"2022/1\":1,\"2022/2\":2,\"2022/3\":3,\"2022/4\":4}}}",
JSONUtil.toJsonStr(beanDemo, JSONConfig.create()));
}
@Data
static class BeanDemo {
Map<String, Map<String, Long>> map1;
}
}

View File

@@ -31,6 +31,6 @@ public class Issues1881Test {
holderContactVOList.add(new ThingsHolderContactVO().setId(1L).setName("1"));
holderContactVOList.add(new ThingsHolderContactVO().setId(2L).setName("2"));
Assert.assertEquals("[{\"name\":\"1\",\"id\":1},{\"name\":\"2\",\"id\":2}]", JSONUtil.parseArray(holderContactVOList).toString());
Assert.assertEquals("[{\"id\":1,\"name\":\"1\"},{\"id\":2,\"name\":\"2\"}]", JSONUtil.parseArray(holderContactVOList).toString());
}
}

View File

@@ -26,7 +26,7 @@ public class JSONNullTest {
" \"device_model\": null,\n" +
" \"device_status_date\": null,\n" +
" \"imsi\": null,\n" +
" \"act_date\": \"2021-07-23T06:23:26.000+00:00\"}", true, true);
" \"act_date\": \"2021-07-23T06:23:26.000+00:00\"}", true);
Assert.assertFalse(bodyjson.containsKey("device_model"));
Assert.assertFalse(bodyjson.containsKey("device_status_date"));
Assert.assertFalse(bodyjson.containsKey("imsi"));

View File

@@ -289,7 +289,7 @@ public class JSONObjectTest {
userA.setDate(new Date());
userA.setSqs(CollectionUtil.newArrayList(new Seq(null), new Seq("seq2")));
JSONObject json = JSONUtil.parseObj(userA, false, true);
JSONObject json = JSONUtil.parseObj(userA, false);
Assert.assertTrue(json.containsKey("a"));
Assert.assertTrue(json.getJSONArray("sqs").getJSONObject(0).containsKey("seq"));
@@ -422,7 +422,6 @@ public class JSONObjectTest {
public void setDateFormatTest() {
JSONConfig jsonConfig = JSONConfig.create();
jsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
jsonConfig.setOrder(true);
JSONObject json = new JSONObject(jsonConfig);
json.append("date", DateUtil.parse("2020-06-05 11:16:11"));
@@ -435,7 +434,6 @@ public class JSONObjectTest {
public void setDateFormatTest2() {
JSONConfig jsonConfig = JSONConfig.create();
jsonConfig.setDateFormat("yyyy#MM#dd");
jsonConfig.setOrder(true);
Date date = DateUtil.parse("2020-06-05 11:16:11");
JSONObject json = new JSONObject(jsonConfig);
@@ -456,7 +454,6 @@ public class JSONObjectTest {
public void setCustomDateFormatTest() {
JSONConfig jsonConfig = JSONConfig.create();
jsonConfig.setDateFormat("#sss");
jsonConfig.setOrder(true);
Date date = DateUtil.parse("2020-06-05 11:16:11");
JSONObject json = new JSONObject(jsonConfig);
@@ -616,7 +613,7 @@ public class JSONObjectTest {
@Test
public void filterIncludeTest() {
JSONObject json1 = JSONUtil.createObj(JSONConfig.create().setOrder(true))
JSONObject json1 = JSONUtil.createObj(JSONConfig.create())
.set("a", "value1")
.set("b", "value2")
.set("c", "value3")
@@ -628,7 +625,7 @@ public class JSONObjectTest {
@Test
public void filterExcludeTest() {
JSONObject json1 = JSONUtil.createObj(JSONConfig.create().setOrder(true))
JSONObject json1 = JSONUtil.createObj(JSONConfig.create())
.set("a", "value1")
.set("b", "value2")
.set("c", "value3")
@@ -640,7 +637,7 @@ public class JSONObjectTest {
@Test
public void editTest() {
JSONObject json1 = JSONUtil.createObj(JSONConfig.create().setOrder(true))
JSONObject json1 = JSONUtil.createObj(JSONConfig.create())
.set("a", "value1")
.set("b", "value2")
.set("c", "value3")
@@ -660,7 +657,7 @@ public class JSONObjectTest {
@Test
public void toUnderLineCaseTest() {
JSONObject json1 = JSONUtil.createObj(JSONConfig.create().setOrder(true))
JSONObject json1 = JSONUtil.createObj(JSONConfig.create())
.set("aKey", "value1")
.set("bJob", "value2")
.set("cGood", "value3")
@@ -675,7 +672,7 @@ public class JSONObjectTest {
@Test
public void nullToEmptyTest() {
JSONObject json1 = JSONUtil.createObj(JSONConfig.create().setOrder(true).setIgnoreNullValue(false))
JSONObject json1 = JSONUtil.createObj(JSONConfig.create().setIgnoreNullValue(false))
.set("a", null)
.set("b", "value2");

View File

@@ -21,7 +21,7 @@ public class TransientTest {
//noinspection MismatchedQueryAndUpdateOfCollection
final JSONObject jsonObject = new JSONObject(detailBill,
JSONConfig.create().setTransientSupport(false));
Assert.assertEquals("{\"bizNo\":\"bizNo\",\"id\":\"3243\"}", jsonObject.toString());
Assert.assertEquals("{\"id\":\"3243\",\"bizNo\":\"bizNo\"}", jsonObject.toString());
}
@Test