优化JsonArray
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
package org.redkale.convert.json;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.*;
|
||||
import java.util.*;
|
||||
import org.redkale.annotation.Nullable;
|
||||
@@ -47,6 +48,11 @@ public class JsonArray extends ArrayList<Object> implements JsonElement {
|
||||
return new JsonArray();
|
||||
}
|
||||
|
||||
public <T> List<T> toList(Type componentType) {
|
||||
Type listType = TypeToken.createParameterizedType(null, ArrayList.class, componentType);
|
||||
return (List) JsonConvert.root().convertFrom(listType, JsonConvert.root().convertTo(this));
|
||||
}
|
||||
|
||||
public JsonArray append(Object value) {
|
||||
super.add(value);
|
||||
return this;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
package org.redkale.convert.json;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.*;
|
||||
import java.util.*;
|
||||
import org.redkale.annotation.Nullable;
|
||||
@@ -56,6 +57,10 @@ public class JsonObject extends LinkedHashMap<String, Object> implements JsonEle
|
||||
return convertFrom(JsonConvert.root().convertTo(bean));
|
||||
}
|
||||
|
||||
public <T> T toObject(Type type) {
|
||||
return (T) JsonConvert.root().convertFrom(type, JsonConvert.root().convertTo(this));
|
||||
}
|
||||
|
||||
public JsonObject append(String key, Object value) {
|
||||
super.put(key, value);
|
||||
return this;
|
||||
|
||||
@@ -568,7 +568,7 @@ public abstract class TypeToken<T> {
|
||||
/**
|
||||
* 动态创建 ParameterizedType
|
||||
*
|
||||
* @param ownerType0 ParameterizedType 的 ownerType
|
||||
* @param ownerType0 ParameterizedType 的 ownerType, 一般为null
|
||||
* @param rawType0 ParameterizedType 的 rawType
|
||||
* @param actualTypeArguments0 ParameterizedType 的 actualTypeArguments
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user