This commit is contained in:
Looly
2020-04-11 10:38:07 +08:00
parent 47be0f4f79
commit 73fd3b849f
21 changed files with 128 additions and 122 deletions

View File

@@ -3,6 +3,7 @@ package cn.hutool.json;
import cn.hutool.core.bean.BeanPath;
import cn.hutool.core.collection.ArrayIter;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.CharUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
@@ -41,7 +42,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
/** 持有原始数据的List */
private final List<Object> rawList;
/** 配置项 */
private JSONConfig config;
private final JSONConfig config;
// -------------------------------------------------------------------------------------------------------------------- Constructor start
/**
@@ -365,14 +366,13 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
return rawList.contains(o);
}
@SuppressWarnings("NullableProblems")
@Override
public Object[] toArray() {
return rawList.toArray();
}
@Override
@SuppressWarnings({"unchecked", "NullableProblems"})
@SuppressWarnings({"unchecked"})
public <T> T[] toArray(T[] a) {
return (T[]) JSONConverter.toArray(this, a.getClass().getComponentType());
}
@@ -600,7 +600,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
init((JSONTokener) source);
} else {
Iterator<?> iter;
if (source.getClass().isArray()) {// 数组
if (ArrayUtil.isArray(source)) {// 数组
iter = new ArrayIter<>(source);
} else if (source instanceof Iterator<?>) {// Iterator
iter = ((Iterator<?>) source);

View File

@@ -46,7 +46,7 @@ public class JSONObject implements JSON, JSONGetter<String>, Map<String, Object>
/** JSON的KV持有Map */
private final Map<String, Object> rawHashMap;
/** 配置项 */
private JSONConfig config;
private final JSONConfig config;
// -------------------------------------------------------------------------------------------------------------------- Constructor start
/**
@@ -677,9 +677,7 @@ public class JSONObject implements JSON, JSONGetter<String>, Map<String, Object>
} else if (source instanceof JSONTokener) {
// JSONTokener
init((JSONTokener) source);
} else if (source instanceof Number) {
// ignore Number
} else {
} else if(BeanUtil.isReadableBean(source.getClass())){
// 普通Bean
this.populateMap(source);
}