This commit is contained in:
Looly
2022-06-07 12:04:23 +08:00
parent c914574c30
commit e5b72ae1ea
3 changed files with 13 additions and 14 deletions

View File

@@ -368,6 +368,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
if(null == object && config.isIgnoreNullValue()){ if(null == object && config.isIgnoreNullValue()){
continue; continue;
} }
this.add(index);
list.add(JSONUtil.wrap(object, this.config)); list.add(JSONUtil.wrap(object, this.config));
} }
return rawList.addAll(index, list); return rawList.addAll(index, list);

View File

@@ -550,11 +550,11 @@ public class JSONUtil {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T getByPath(final JSON json, final String expression, final T defaultValue) { public static <T> T getByPath(final JSON json, final String expression, final T defaultValue) {
if((null == json || StrUtil.isBlank(expression))){ if ((null == json || StrUtil.isBlank(expression))) {
return defaultValue; return defaultValue;
} }
if(null != defaultValue){ if (null != defaultValue) {
final Class<T> type = (Class<T>) defaultValue.getClass(); final Class<T> type = (Class<T>) defaultValue.getClass();
return ObjUtil.defaultIfNull(json.getByPath(expression, type), defaultValue); return ObjUtil.defaultIfNull(json.getByPath(expression, type), defaultValue);
} }
@@ -701,7 +701,6 @@ public class JSONUtil {
* 在需要的时候包装对象<br> * 在需要的时候包装对象<br>
* 包装包括: * 包装包括:
* <ul> * <ul>
* <li>{@code null} =》 {@code JSONNull.NULL}</li>
* <li>array or collection =》 JSONArray</li> * <li>array or collection =》 JSONArray</li>
* <li>map =》 JSONObject</li> * <li>map =》 JSONObject</li>
* <li>standard property (Double, String, et al) =》 原对象</li> * <li>standard property (Double, String, et al) =》 原对象</li>
@@ -719,7 +718,6 @@ public class JSONUtil {
return null; return null;
} }
if (object instanceof JSON // if (object instanceof JSON //
|| ObjUtil.isNull(object) //
|| object instanceof JSONString // || object instanceof JSONString //
|| object instanceof CharSequence // || object instanceof CharSequence //
|| object instanceof Number // || object instanceof Number //
@@ -743,13 +741,13 @@ public class JSONUtil {
try { try {
// fix issue#1399@Github // fix issue#1399@Github
if(object instanceof SQLException){ if (object instanceof SQLException) {
return object.toString(); return object.toString();
} }
// JSONArray // JSONArray
if (object instanceof Iterable || ArrayUtil.isArray(object)) { if (object instanceof Iterable || ArrayUtil.isArray(object)) {
if(object instanceof byte[]){ if (object instanceof byte[]) {
// issue#I59LW4 // issue#I59LW4
// json内容中的bytes默认转为Base64 // json内容中的bytes默认转为Base64
return Base64.encode((byte[]) object); return Base64.encode((byte[]) object);

View File

@@ -119,7 +119,7 @@ public class ObjectMapper {
} }
/** /**
* 初始化 * 将给定对象转换为{@link JSONArray}
* *
* @param jsonArray 目标{@link JSONArray} * @param jsonArray 目标{@link JSONArray}
* @param filter 键值对过滤编辑器,可以通过实现此接口,完成解析前对值的过滤和修改操作,{@code null}表示不过滤 * @param filter 键值对过滤编辑器,可以通过实现此接口,完成解析前对值的过滤和修改操作,{@code null}表示不过滤
@@ -139,7 +139,7 @@ public class ObjectMapper {
} else if (source instanceof CharSequence) { } else if (source instanceof CharSequence) {
// JSON字符串 // JSON字符串
mapFromStr((CharSequence) source, jsonArray, filter); mapFromStr((CharSequence) source, jsonArray, filter);
}else if (source instanceof Reader) { } else if (source instanceof Reader) {
mapFromTokener(new JSONTokener((Reader) source, jsonArray.getConfig()), jsonArray, filter); mapFromTokener(new JSONTokener((Reader) source, jsonArray.getConfig()), jsonArray, filter);
} else if (source instanceof InputStream) { } else if (source instanceof InputStream) {
mapFromTokener(new JSONTokener((InputStream) source, jsonArray.getConfig()), jsonArray, filter); mapFromTokener(new JSONTokener((InputStream) source, jsonArray.getConfig()), jsonArray, filter);