mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add test
This commit is contained in:
parent
7d3c567961
commit
897bd5d801
@ -567,6 +567,29 @@ public class JSONUtil {
|
||||
return JSONStrFormatter.format(jsonStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON对象是否为空,以下情况返回true<br>
|
||||
* <ul>
|
||||
* <li>null</li>
|
||||
* <li>{@link JSONArray#isEmpty()}</li>
|
||||
* <li>{@link JSONObject#isEmpty()}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param json JSONObject或JSONArray
|
||||
* @return 是否为空
|
||||
*/
|
||||
public static boolean isEmpty(final JSON json){
|
||||
if(null == json){
|
||||
return true;
|
||||
}
|
||||
if(json instanceof JSONObject){
|
||||
return ((JSONObject) json).isEmpty();
|
||||
} else if(json instanceof JSONArray){
|
||||
return ((JSONArray) json).isEmpty();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为JSON类型字符串,首尾都为大括号或中括号判定为JSON字符串
|
||||
*
|
||||
|
24
hutool-json/src/test/java/cn/hutool/json/Issue2564Test.java
Executable file
24
hutool-json/src/test/java/cn/hutool/json/Issue2564Test.java
Executable file
@ -0,0 +1,24 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Issue2564Test {
|
||||
|
||||
/**
|
||||
* 实力类 没有get set方法,不能被认为是一个bean
|
||||
*/
|
||||
@Test()
|
||||
public void emptyToBeanTest(){
|
||||
final String x = "{}";
|
||||
final A a = JSONUtil.toBean(x, JSONConfig.of().setIgnoreError(true), A.class);
|
||||
Assert.assertNull(a);
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class A{
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user