mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
当用户选择ignoreError时,错误对象转JSON也忽略
This commit is contained in:
@@ -113,8 +113,11 @@ public class ObjectMapper {
|
||||
// TODO 过滤器对Bean无效,需补充。
|
||||
mapFromBean(source, jsonObject);
|
||||
} else {
|
||||
// 不支持对象类型转换为JSONObject
|
||||
throw new JSONException("Unsupported type [{}] to JSONObject!", source.getClass());
|
||||
if(false == jsonObject.getConfig().isIgnoreError()){
|
||||
// 不支持对象类型转换为JSONObject
|
||||
throw new JSONException("Unsupported type [{}] to JSONObject!", source.getClass());
|
||||
}
|
||||
// 如果用户选择跳过异常,则跳过此值转换
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -45,7 +45,7 @@ public class JSONUtilTest {
|
||||
*/
|
||||
@Test
|
||||
public void parseNumberTest2() {
|
||||
final JSONObject json = JSONUtil.parseObj(123L);
|
||||
final JSONObject json = JSONUtil.parseObj(123L, JSONConfig.create().setIgnoreError(true));
|
||||
Assert.assertEquals(new JSONObject(), json);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user