mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
add sort
This commit is contained in:
18
hutool-json/src/test/java/cn/hutool/json/IssueI4RBZ4Test.java
Executable file
18
hutool-json/src/test/java/cn/hutool/json/IssueI4RBZ4Test.java
Executable file
@@ -0,0 +1,18 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* https://gitee.com/dromara/hutool/issues/I4RBZ4
|
||||
*/
|
||||
public class IssueI4RBZ4Test {
|
||||
|
||||
@Test
|
||||
public void sortTest(){
|
||||
String jsonStr = "{\"id\":\"123\",\"array\":[1,2,3],\"outNum\":356,\"body\":{\"ava1\":\"20220108\",\"use\":1,\"ava2\":\"20230108\"},\"name\":\"John\"}";
|
||||
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(jsonStr, JSONConfig.create().setNatureKeyComparator());
|
||||
Assert.assertEquals("{\"array\":[1,2,3],\"body\":{\"ava1\":\"20220108\",\"ava2\":\"20230108\",\"use\":1},\"id\":\"123\",\"name\":\"John\",\"outNum\":356}", jsonObject.toString());
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,19 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class issues1881Test {
|
||||
public class Issues1881Test {
|
||||
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
public class ThingsHolderContactVO implements Serializable {
|
||||
static class ThingsHolderContactVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -8727337936070932370L;
|
||||
private Long id;
|
||||
@@ -30,6 +31,6 @@ public class issues1881Test {
|
||||
holderContactVOList.add(new ThingsHolderContactVO().setId(1L).setName("1"));
|
||||
holderContactVOList.add(new ThingsHolderContactVO().setId(2L).setName("2"));
|
||||
|
||||
Console.log(JSONUtil.parseArray(holderContactVOList));
|
||||
Assert.assertEquals("[{\"name\":\"1\",\"id\":1},{\"name\":\"2\",\"id\":2}]", JSONUtil.parseArray(holderContactVOList).toString());
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@@ -33,6 +34,7 @@ public class JSONStrFormatterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void formatTest4(){
|
||||
String jsonStr = "{\"employees\":[{\"firstName\":\"Bill\",\"lastName\":\"Gates\"},{\"firstName\":\"George\",\"lastName\":\"Bush\"},{\"firstName\":\"Thomas\",\"lastName\":\"Carter\"}]}";
|
||||
Console.log(JSONUtil.formatJsonStr(jsonStr));
|
||||
|
||||
@@ -36,7 +36,7 @@ public class JSONUtilTest {
|
||||
@Test(expected = JSONException.class)
|
||||
public void parseNumberTest() {
|
||||
JSONArray json = JSONUtil.parseArray(123L);
|
||||
Console.log(json);
|
||||
Assert.assertNotNull(json);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user