mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
当用户选择ignoreError时,错误对象转JSON也忽略
This commit is contained in:
parent
1ac0a904c0
commit
317d8ee527
@ -12,6 +12,7 @@
|
|||||||
* 【core 】 StrUtil增加commonPrefix和commonSuffix方法(pr#3007@Github)
|
* 【core 】 StrUtil增加commonPrefix和commonSuffix方法(pr#3007@Github)
|
||||||
* 【core 】 NumberUtil增加重载parseXXX方法, 解析失败返回默认值(pr#3007@Github)
|
* 【core 】 NumberUtil增加重载parseXXX方法, 解析失败返回默认值(pr#3007@Github)
|
||||||
* 【core 】 FileUtil增加readLines重载,支持filter(pr#3006@Github)
|
* 【core 】 FileUtil增加readLines重载,支持filter(pr#3006@Github)
|
||||||
|
* 【json 】 当用户选择ignoreError时,错误对象转JSON也忽略
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【crypto】 修复NoSuchMethodError未捕获问题(issue#2966@Github)
|
* 【crypto】 修复NoSuchMethodError未捕获问题(issue#2966@Github)
|
||||||
|
@ -113,8 +113,11 @@ public class ObjectMapper {
|
|||||||
// TODO 过滤器对Bean无效,需补充。
|
// TODO 过滤器对Bean无效,需补充。
|
||||||
mapFromBean(source, jsonObject);
|
mapFromBean(source, jsonObject);
|
||||||
} else {
|
} else {
|
||||||
// 不支持对象类型转换为JSONObject
|
if(false == jsonObject.getConfig().isIgnoreError()){
|
||||||
throw new JSONException("Unsupported type [{}] to JSONObject!", source.getClass());
|
// 不支持对象类型转换为JSONObject
|
||||||
|
throw new JSONException("Unsupported type [{}] to JSONObject!", source.getClass());
|
||||||
|
}
|
||||||
|
// 如果用户选择跳过异常,则跳过此值转换
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public class JSONUtilTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void parseNumberTest2() {
|
public void parseNumberTest2() {
|
||||||
final JSONObject json = JSONUtil.parseObj(123L);
|
final JSONObject json = JSONUtil.parseObj(123L, JSONConfig.create().setIgnoreError(true));
|
||||||
Assert.assertEquals(new JSONObject(), json);
|
Assert.assertEquals(new JSONObject(), json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user