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
b884cdaedd
commit
6394b41cb1
@ -161,7 +161,7 @@ public class ObjectMapper {
|
|||||||
} else if (source instanceof JSONTokener) {
|
} else if (source instanceof JSONTokener) {
|
||||||
mapFromTokener((JSONTokener) source, jsonArray, filter);
|
mapFromTokener((JSONTokener) source, jsonArray, filter);
|
||||||
} else {
|
} else {
|
||||||
Iterator<?> iter;
|
final Iterator<?> iter;
|
||||||
if (ArrayUtil.isArray(source)) {// 数组
|
if (ArrayUtil.isArray(source)) {// 数组
|
||||||
iter = new ArrayIter<>(source);
|
iter = new ArrayIter<>(source);
|
||||||
} else if (source instanceof Iterator<?>) {// Iterator
|
} else if (source instanceof Iterator<?>) {// Iterator
|
||||||
@ -169,7 +169,11 @@ public class ObjectMapper {
|
|||||||
} else if (source instanceof Iterable<?>) {// Iterable
|
} else if (source instanceof Iterable<?>) {// Iterable
|
||||||
iter = ((Iterable<?>) source).iterator();
|
iter = ((Iterable<?>) source).iterator();
|
||||||
} else {
|
} else {
|
||||||
throw new JSONException("JSONArray initial value should be a string or collection or array.");
|
if(false == jsonArray.getConfig().isIgnoreError()){
|
||||||
|
throw new JSONException("JSONArray initial value should be a string or collection or array.");
|
||||||
|
}
|
||||||
|
// 如果用户选择跳过异常,则跳过此值转换
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final JSONConfig config = jsonArray.getConfig();
|
final JSONConfig config = jsonArray.getConfig();
|
||||||
|
@ -31,6 +31,16 @@ public class JSONUtilTest {
|
|||||||
Console.log(jsonArray);
|
Console.log(jsonArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数字解析为JSONArray报错
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void parseNumberToJSONArrayTest2() {
|
||||||
|
final JSONArray json = JSONUtil.parseArray(123L,
|
||||||
|
JSONConfig.create().setIgnoreError(true));
|
||||||
|
Assert.assertNotNull(json);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数字解析为JSONArray报错
|
* 数字解析为JSONArray报错
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user