This commit is contained in:
Looly
2022-09-04 23:42:15 +08:00
parent 4a2b5b548f
commit ace5fcd89b
6 changed files with 61 additions and 33 deletions

View File

@@ -207,9 +207,8 @@ public final class InternalJSONUtil {
* @param key 键
* @param value 值
* @param predicate 属性过滤器,{@link Predicate#test(Object)}为{@code true}保留
* @return JSONObject
*/
public static JSONObject propertyPut(final JSONObject jsonObject, final Object key, final Object value, final Predicate<MutableEntry<String, Object>> predicate) {
public static void propertyPut(final JSONObject jsonObject, final Object key, final Object value, final Predicate<MutableEntry<String, Object>> predicate) {
final String[] path = StrUtil.splitToArray(Convert.toStr(key), CharUtil.DOT);
final int last = path.length - 1;
JSONObject target = jsonObject;
@@ -223,7 +222,6 @@ public final class InternalJSONUtil {
target = nextTarget;
}
target.set(path[last], value, predicate);
return jsonObject;
}
/**
@@ -296,11 +294,10 @@ public final class InternalJSONUtil {
*
* @param str 字符串
* @param writer Writer
* @return Writer
* @throws IORuntimeException IO异常
*/
public static Writer quote(final String str, final Writer writer) throws IORuntimeException {
return quote(str, writer, true);
public static void quote(final String str, final Writer writer) throws IORuntimeException {
quote(str, writer, true);
}
/**

View File

@@ -107,7 +107,9 @@ public interface JSON extends Cloneable, Serializable {
* @see BeanPath#get(Object)
* @since 4.0.6
*/
<T> T getByPath(String expression, Class<T> resultType);
default <T> T getByPath(final String expression, final Class<T> resultType){
return JSONConverterOld.jsonConvert(resultType, getByPath(expression), getConfig());
}
/**
* 格式化打印JSON缩进为4个空格
@@ -159,17 +161,6 @@ public interface JSON extends Cloneable, Serializable {
*/
Writer write(Writer writer, int indentFactor, int indent, final Predicate<MutableEntry<Object, Object>> predicate) throws JSONException;
/**
* 转为实体类对象,转换异常将被抛出
*
* @param <T> Bean类型
* @param clazz 实体类
* @return 实体类对象
*/
default <T> T toBean(final Class<T> clazz) {
return toBean((Type) clazz);
}
/**
* 转为实体类对象
*

View File

@@ -8,7 +8,6 @@ import cn.hutool.core.lang.mutable.MutableEntry;
import cn.hutool.core.lang.mutable.MutableObj;
import cn.hutool.core.text.StrJoiner;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.json.convert.JSONConverterOld;
import cn.hutool.json.mapper.ArrayMapper;
import cn.hutool.json.serialize.JSONWriter;
@@ -193,11 +192,6 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
return (index < 0 || index >= this.size()) ? defaultValue : this.rawList.get(index);
}
@Override
public <T> T getByPath(final String expression, final Class<T> resultType) {
return JSONConverterOld.jsonConvert(resultType, getByPath(expression), getConfig());
}
/**
* Append an object value. This increases the array's length by one. <br>
* 加入元素,数组长度+1等同于 {@link JSONArray#add(Object)}

View File

@@ -5,7 +5,6 @@ import cn.hutool.core.lang.mutable.MutableEntry;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.map.MapWrapper;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.json.convert.JSONConverterOld;
import cn.hutool.json.mapper.ObjectMapper;
import cn.hutool.json.serialize.JSONWriter;
@@ -183,11 +182,6 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
return this.getOrDefault(key, defaultValue);
}
@Override
public <T> T getByPath(final String expression, final Class<T> resultType) {
return JSONConverterOld.jsonConvert(resultType, getByPath(expression), getConfig());
}
/**
* PUT 键值对到JSONObject中在忽略null模式下如果值为{@code null},将此键移除
*

View File

@@ -1,7 +1,6 @@
package cn.hutool.json;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.convert.JSONConverterOld;
import cn.hutool.json.serialize.JSONDeserializer;
import cn.hutool.json.serialize.JSONString;
@@ -29,8 +28,8 @@ public class JSONSupport implements JSONString, JSONDeserializer<Object> {
*/
@Override
public Object deserialize(final JSON json) {
final JSONSupport support = JSONConverterOld.jsonToBean(getClass(), json, false);
BeanUtil.copyProperties(support, this);
// TODO 经过两次转换,效率差,待优化
BeanUtil.copyProperties(json.toBean(getClass()), this);
return this;
}