mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -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";
|
||||
|
@@ -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());
|
||||
|
Reference in New Issue
Block a user