mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix bug and add method
This commit is contained in:
@@ -45,6 +45,17 @@ public class JSONArrayTest {
|
||||
Assert.assertEquals(array.get(0), "value1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseWithNullTest() {
|
||||
String jsonStr = "[{\"grep\":\"4.8\",\"result\":\"右\"},{\"grep\":\"4.8\",\"result\":null}]";
|
||||
JSONArray jsonArray = JSONUtil.parseArray(jsonStr);
|
||||
Assert.assertFalse(jsonArray.getJSONObject(1).containsKey("result"));
|
||||
|
||||
// 不忽略null,则null的键值对被保留
|
||||
jsonArray = new JSONArray(jsonStr, false);
|
||||
Assert.assertTrue(jsonArray.getJSONObject(1).containsKey("result"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseFileTest() {
|
||||
JSONArray array = JSONUtil.readJSONArray(FileUtil.file("exam_test.json"), CharsetUtil.CHARSET_UTF_8);
|
||||
|
@@ -186,11 +186,11 @@ public class JSONObjectTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toBeanTest3() {
|
||||
public void toBeanWithNullTest() {
|
||||
String jsonStr = "{'data':{'userName':'ak','password': null}}";
|
||||
Console.log(JSONUtil.parseObj(jsonStr));
|
||||
UserWithMap user = JSONUtil.toBean(JSONUtil.parseObj(jsonStr), UserWithMap.class);
|
||||
// Bean默认忽略null
|
||||
Assert.assertFalse(user.getData().containsKey("password"));
|
||||
Assert.assertTrue(user.getData().containsKey("password"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user