mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -3,32 +3,34 @@ package cn.hutool.json;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class IssueI6LBZATest {
|
||||
@Test
|
||||
public void parseJSONStringTest() {
|
||||
final String a = "\"a\"";
|
||||
final JSON parse = JSONUtil.parse(a);
|
||||
Assert.assertEquals(JSONString.class, parse.getClass());
|
||||
final Object parse = JSONUtil.parse(a);
|
||||
Assert.assertEquals(String.class, parse.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseJSONStringTest2() {
|
||||
final String a = "'a'";
|
||||
final JSON parse = JSONUtil.parse(a);
|
||||
Assert.assertEquals(JSONString.class, parse.getClass());
|
||||
final Object parse = JSONUtil.parse(a);
|
||||
Assert.assertEquals(String.class, parse.getClass());
|
||||
}
|
||||
|
||||
@Test(expected = JSONException.class)
|
||||
public void parseJSONErrorTest() {
|
||||
final String a = "a";
|
||||
final JSON parse = JSONUtil.parse(a);
|
||||
Assert.assertEquals(JSONString.class, parse.getClass());
|
||||
final Object parse = JSONUtil.parse(a);
|
||||
Assert.assertEquals(String.class, parse.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseJSONNumberTest() {
|
||||
final String a = "123";
|
||||
final JSON parse = JSONUtil.parse(a);
|
||||
Assert.assertEquals(JSONNumber.class, parse.getClass());
|
||||
final Object parse = JSONUtil.parse(a);
|
||||
Assert.assertEquals(BigDecimal.class, parse.getClass());
|
||||
}
|
||||
}
|
||||
|
@@ -42,8 +42,7 @@ public class JSONArrayTest {
|
||||
@Test
|
||||
public void addNullTest() {
|
||||
final List<String> aaa = ListUtil.view("aaa", null);
|
||||
final String jsonStr = JSONUtil.toJsonStr(JSONUtil.parse(aaa,
|
||||
JSONConfig.of().setIgnoreNullValue(false)));
|
||||
final String jsonStr = JSONUtil.toJsonStr(JSONUtil.parse(aaa, JSONConfig.of().setIgnoreNullValue(false)));
|
||||
Assert.assertEquals("[\"aaa\",null]", jsonStr);
|
||||
}
|
||||
|
||||
|
@@ -23,7 +23,7 @@ public class JSONPathTest {
|
||||
@Test
|
||||
public void getByPathTest2(){
|
||||
final String str = "{'accountId':111}";
|
||||
final JSON json = JSONUtil.parse(str);
|
||||
final JSON json = (JSON) JSONUtil.parse(str);
|
||||
final Long accountId = JSONUtil.getByPath(json, "$.accountId", 0L);
|
||||
Assert.assertEquals(111L, accountId.longValue());
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.math.NumberUtil;
|
||||
import cn.hutool.json.serialize.JSONStringer;
|
||||
@@ -235,9 +236,11 @@ public class JSONUtilTest {
|
||||
Assert.assertEquals("<key1>v1</key1><key2>a</key2><key2>b</key2><key2>c</key2>", xmlStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = JSONException.class)
|
||||
public void toJsonStrOfStringTest(){
|
||||
final String a = "a";
|
||||
|
||||
// 普通字符串不能解析为JSON字符串,必须由双引号或者单引号包裹
|
||||
final String s = JSONUtil.toJsonStr(a);
|
||||
Assert.assertEquals(a, s);
|
||||
}
|
||||
|
Reference in New Issue
Block a user