mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -16,6 +16,7 @@ import cn.hutool.json.serialize.JSONWriter;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
@@ -196,7 +197,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
this(DEFAULT_CAPACITY, jsonConfig);
|
||||
init(object);
|
||||
}
|
||||
// -------------------------------------------------------------------------------------------------------------------- Constructor start
|
||||
// -------------------------------------------------------------------------------------------------------------------- Constructor end
|
||||
|
||||
@Override
|
||||
public JSONConfig getConfig() {
|
||||
@@ -291,6 +292,11 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toBean(Type type) {
|
||||
return JSON.super.toBean(type, config.isIgnoreError());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据给定名列表,与其位置对应的值组成JSONObject
|
||||
*
|
||||
|
@@ -22,6 +22,7 @@ import cn.hutool.json.serialize.JSONWriter;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Collection;
|
||||
@@ -274,6 +275,11 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toBean(Type type) {
|
||||
return JSON.super.toBean(type, this.config.isIgnoreError());
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定KEY列表的值组成新的JSONArray
|
||||
*
|
||||
|
@@ -421,6 +421,21 @@ public class JSONUtil {
|
||||
return toBean(parseObj(jsonString), beanClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON字符串转为实体类对象,转换异常将被抛出<br>
|
||||
* 通过{@link JSONConfig}可选是否忽略大小写、忽略null等配置
|
||||
*
|
||||
* @param <T> Bean类型
|
||||
* @param jsonString JSON字符串
|
||||
* @param config JSON配置
|
||||
* @param beanClass 实体类对象
|
||||
* @return 实体类对象
|
||||
* @since 5.8.0
|
||||
*/
|
||||
public static <T> T toBean(String jsonString, JSONConfig config, Class<T> beanClass) {
|
||||
return toBean(parseObj(jsonString, config), beanClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转为实体类对象,转换异常将被抛出
|
||||
*
|
||||
@@ -458,7 +473,7 @@ public class JSONUtil {
|
||||
* @since 4.3.2
|
||||
*/
|
||||
public static <T> T toBean(String jsonString, Type beanType, boolean ignoreError) {
|
||||
return toBean(parse(jsonString), beanType, ignoreError);
|
||||
return parse(jsonString, JSONConfig.create().setIgnoreError(ignoreError)).toBean(beanType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user