This commit is contained in:
Looly
2020-04-11 10:38:07 +08:00
parent 47be0f4f79
commit 73fd3b849f
21 changed files with 128 additions and 122 deletions

View File

@@ -11,7 +11,7 @@ public class CustomSerializeTest {
@Test
public void serializeTest() {
JSONUtil.putSerializer(CustomBean.class, (JSONObjectSerializer<CustomBean>) (json, bean) -> json.put("customName", bean.name));
JSONUtil.putSerializer(CustomBean.class, (JSONObjectSerializer<CustomBean>) (json, bean) -> json.set("customName", bean.name));
CustomBean customBean = new CustomBean();
customBean.name = "testName";

View File

@@ -25,6 +25,24 @@ public class JSONUtilTest {
Console.log(jsonArray);
}
/**
* 数字解析为JSONArray报错
*/
@Test(expected = JSONException.class)
public void parseNumberTest(){
JSONArray json = JSONUtil.parseArray(123L);
Console.log(json);
}
/**
* 数字解析为JSONObject忽略
*/
@Test
public void parseNumberTest2(){
JSONObject json = JSONUtil.parseObj(123L);
Assert.assertEquals(new JSONObject(), json);
}
@Test
public void toJsonStrTest() {
UserA a1 = new UserA();
@@ -67,9 +85,9 @@ public class JSONUtilTest {
public void toJsonStrTest3() {
// 验证某个字段为JSON字符串时转义是否规范
JSONObject object = new JSONObject(true);
object.put("name", "123123");
object.put("value", "\\");
object.put("value2", "</");
object.set("name", "123123");
object.set("value", "\\");
object.set("value2", "</");
HashMap<String, String> map = MapUtil.newHashMap();
map.put("user", object.toString());