mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
ace5fcd89b
commit
92d1843fbd
@ -13,7 +13,6 @@ import cn.hutool.core.text.StrUtil;
|
|||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.CharUtil;
|
import cn.hutool.core.util.CharUtil;
|
||||||
import cn.hutool.core.util.ObjUtil;
|
import cn.hutool.core.util.ObjUtil;
|
||||||
import cn.hutool.json.convert.JSONConverterOld;
|
|
||||||
import cn.hutool.json.serialize.JSONString;
|
import cn.hutool.json.serialize.JSONString;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -257,8 +256,7 @@ public final class InternalJSONUtil {
|
|||||||
.setIgnoreNullValue(config.isIgnoreNullValue())
|
.setIgnoreNullValue(config.isIgnoreNullValue())
|
||||||
.setTransientSupport(config.isTransientSupport())
|
.setTransientSupport(config.isTransientSupport())
|
||||||
// 使用JSON转换器
|
// 使用JSON转换器
|
||||||
.setConverter((type, value) ->
|
.setConverter(config.getConverter());
|
||||||
JSONConverterOld.convertWithCheck(type, value, null, config.isIgnoreError()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,7 +2,6 @@ package cn.hutool.json;
|
|||||||
|
|
||||||
import cn.hutool.core.bean.BeanPath;
|
import cn.hutool.core.bean.BeanPath;
|
||||||
import cn.hutool.core.lang.mutable.MutableEntry;
|
import cn.hutool.core.lang.mutable.MutableEntry;
|
||||||
import cn.hutool.json.convert.JSONConverterOld;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
@ -107,8 +106,9 @@ public interface JSON extends Cloneable, Serializable {
|
|||||||
* @see BeanPath#get(Object)
|
* @see BeanPath#get(Object)
|
||||||
* @since 4.0.6
|
* @since 4.0.6
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
default <T> T getByPath(final String expression, final Class<T> resultType){
|
default <T> T getByPath(final String expression, final Class<T> resultType){
|
||||||
return JSONConverterOld.jsonConvert(resultType, getByPath(expression), getConfig());
|
return (T) getConfig().getConverter().convert(resultType, getByPath(expression));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -169,7 +169,8 @@ public interface JSON extends Cloneable, Serializable {
|
|||||||
* @return 实体类对象
|
* @return 实体类对象
|
||||||
* @since 4.3.2
|
* @since 4.3.2
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
default <T> T toBean(final Type type) {
|
default <T> T toBean(final Type type) {
|
||||||
return JSONConverterOld.jsonConvert(type, this, getConfig());
|
return (T) getConfig().getConverter().convert(type, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cn.hutool.json;
|
package cn.hutool.json;
|
||||||
|
|
||||||
import cn.hutool.core.comparator.CompareUtil;
|
import cn.hutool.core.comparator.CompareUtil;
|
||||||
|
import cn.hutool.core.convert.Converter;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@ -38,7 +39,6 @@ public class JSONConfig implements Serializable {
|
|||||||
* 是否支持transient关键字修饰和@Transient注解,如果支持,被修饰的字段或方法对应的字段将被忽略。
|
* 是否支持transient关键字修饰和@Transient注解,如果支持,被修饰的字段或方法对应的字段将被忽略。
|
||||||
*/
|
*/
|
||||||
private boolean transientSupport = true;
|
private boolean transientSupport = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否去除末尾多余0,例如如果为true,5.0返回5
|
* 是否去除末尾多余0,例如如果为true,5.0返回5
|
||||||
*/
|
*/
|
||||||
@ -47,6 +47,10 @@ public class JSONConfig implements Serializable {
|
|||||||
* 是否检查重复key
|
* 是否检查重复key
|
||||||
*/
|
*/
|
||||||
private boolean checkDuplicate;
|
private boolean checkDuplicate;
|
||||||
|
/**
|
||||||
|
* 自定义的类型转换器,用于在序列化、反序列化操作中实现对象类型转换
|
||||||
|
*/
|
||||||
|
private Converter converter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建默认的配置项
|
* 创建默认的配置项
|
||||||
@ -237,4 +241,20 @@ public class JSONConfig implements Serializable {
|
|||||||
this.checkDuplicate = checkDuplicate;
|
this.checkDuplicate = checkDuplicate;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取自定义的类型转换器,用于在序列化、反序列化操作中实现对象类型转换
|
||||||
|
* @return 转换器
|
||||||
|
*/
|
||||||
|
public Converter getConverter() {
|
||||||
|
return converter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置自定义的类型转换器,用于在序列化、反序列化操作中实现对象类型转换
|
||||||
|
* @param converter 转换器
|
||||||
|
*/
|
||||||
|
public void setConverter(final Converter converter) {
|
||||||
|
this.converter = converter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package cn.hutool.json;
|
|||||||
import cn.hutool.core.convert.ConvertException;
|
import cn.hutool.core.convert.ConvertException;
|
||||||
import cn.hutool.core.lang.getter.OptNullBasicTypeFromObjectGetter;
|
import cn.hutool.core.lang.getter.OptNullBasicTypeFromObjectGetter;
|
||||||
import cn.hutool.core.util.ObjUtil;
|
import cn.hutool.core.util.ObjUtil;
|
||||||
import cn.hutool.json.convert.JSONConverterOld;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -163,12 +162,13 @@ public interface JSONGetter<K> extends OptNullBasicTypeFromObjectGetter<K> {
|
|||||||
* @throws ConvertException 转换异常
|
* @throws ConvertException 转换异常
|
||||||
* @since 3.0.8
|
* @since 3.0.8
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
default <T> T get(final K key, final Class<T> type) throws ConvertException {
|
default <T> T get(final K key, final Class<T> type) throws ConvertException {
|
||||||
final Object value = this.getObj(key);
|
final Object value = this.getObj(key);
|
||||||
if (ObjUtil.isNull(value)) {
|
if (ObjUtil.isNull(value)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSONConverterOld.jsonConvert(type, value, getConfig());
|
return (T) getConfig().getConverter().convert(type, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
hutool-json/src/main/java/cn/hutool/json/convert/JSONCompositeConverter.java
Executable file
16
hutool-json/src/main/java/cn/hutool/json/convert/JSONCompositeConverter.java
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
package cn.hutool.json.convert;
|
||||||
|
|
||||||
|
import cn.hutool.core.convert.CompositeConverter;
|
||||||
|
import cn.hutool.core.convert.ConvertException;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
public class JSONCompositeConverter extends CompositeConverter {
|
||||||
|
|
||||||
|
public static final JSONCompositeConverter INSTANCE = new JSONCompositeConverter();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T convert(final Type type, final Object value, final T defaultValue, final boolean isCustomFirst) throws ConvertException {
|
||||||
|
return super.convert(type, value, defaultValue, isCustomFirst);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user