mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -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);
|
||||||
|
@@ -286,7 +286,7 @@ public class JSONUtil {
|
|||||||
/**
|
/**
|
||||||
* 转为JSON字符串,并写出到write
|
* 转为JSON字符串,并写出到write
|
||||||
*
|
*
|
||||||
* @param json JSON
|
* @param json JSON
|
||||||
* @param writer Writer
|
* @param writer Writer
|
||||||
* @since 5.3.3
|
* @since 5.3.3
|
||||||
*/
|
*/
|
||||||
@@ -322,7 +322,7 @@ public class JSONUtil {
|
|||||||
/**
|
/**
|
||||||
* 转换为JSON字符串
|
* 转换为JSON字符串
|
||||||
*
|
*
|
||||||
* @param obj 被转为JSON的对象
|
* @param obj 被转为JSON的对象
|
||||||
* @param jsonConfig JSON配置
|
* @param jsonConfig JSON配置
|
||||||
* @return JSON字符串
|
* @return JSON字符串
|
||||||
* @since 5.7.12
|
* @since 5.7.12
|
||||||
@@ -340,7 +340,7 @@ public class JSONUtil {
|
|||||||
/**
|
/**
|
||||||
* 转换为JSON字符串并写出到writer
|
* 转换为JSON字符串并写出到writer
|
||||||
*
|
*
|
||||||
* @param obj 被转为JSON的对象
|
* @param obj 被转为JSON的对象
|
||||||
* @param writer Writer
|
* @param writer Writer
|
||||||
* @since 5.3.3
|
* @since 5.3.3
|
||||||
*/
|
*/
|
||||||
@@ -540,9 +540,9 @@ public class JSONUtil {
|
|||||||
* person.friends[5].name
|
* person.friends[5].name
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param <T> 值类型
|
* @param <T> 值类型
|
||||||
* @param json {@link JSON}
|
* @param json {@link JSON}
|
||||||
* @param expression 表达式
|
* @param expression 表达式
|
||||||
* @param defaultValue 默认值
|
* @param defaultValue 默认值
|
||||||
* @return 对象
|
* @return 对象
|
||||||
* @see JSON#getByPath(String)
|
* @see JSON#getByPath(String)
|
||||||
@@ -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);
|
||||||
|
@@ -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);
|
||||||
|
Reference in New Issue
Block a user