mirror of
https://e.coding.net/circlecloud/GsonAgent.git
synced 2024-11-24 02:08:48 +00:00
格式化代码 修复nameWithoutQuotes方法未生效的问题...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
628868dadc
commit
25375227f6
@ -17,60 +17,60 @@ import cn.citycraft.GsonAgent.api.stream.JsonWriter;
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
public interface Gson {
|
||||
public <T> T fromJson(JsonElement json, Class<T> classOfT) throws JsonSyntaxException;
|
||||
public <T> T fromJson(JsonElement json, Class<T> classOfT) throws JsonSyntaxException;
|
||||
|
||||
public <T> T fromJson(JsonElement json, Type typeOfT) throws JsonSyntaxException;
|
||||
public <T> T fromJson(JsonElement json, Type typeOfT) throws JsonSyntaxException;
|
||||
|
||||
public <T> T fromJson(JsonReader reader, Type typeOfT) throws JsonIOException, JsonSyntaxException;
|
||||
public <T> T fromJson(JsonReader reader, Type typeOfT) throws JsonIOException, JsonSyntaxException;
|
||||
|
||||
public <T> T fromJson(Reader json, Class<T> classOfT) throws JsonSyntaxException, JsonIOException;
|
||||
public <T> T fromJson(Reader json, Class<T> classOfT) throws JsonSyntaxException, JsonIOException;
|
||||
|
||||
public <T> T fromJson(Reader json, Type typeOfT) throws JsonIOException, JsonSyntaxException;
|
||||
public <T> T fromJson(Reader json, Type typeOfT) throws JsonIOException, JsonSyntaxException;
|
||||
|
||||
/**
|
||||
* @param result
|
||||
* Json字符串
|
||||
* @param clazz
|
||||
* 模型类
|
||||
* @return
|
||||
*/
|
||||
public <T> T fromJson(final String result, Class<T> clazz) throws JsonSyntaxException;
|
||||
/**
|
||||
* @param result
|
||||
* Json字符串
|
||||
* @param clazz
|
||||
* 模型类
|
||||
* @return
|
||||
*/
|
||||
public <T> T fromJson(final String result, Class<T> clazz) throws JsonSyntaxException;
|
||||
|
||||
public <T> T fromJson(String json, Type typeOfT) throws JsonSyntaxException;
|
||||
public <T> T fromJson(String json, Type typeOfT) throws JsonSyntaxException;
|
||||
|
||||
public <T> TypeAdapter<T> getAdapter(Class<T> type);
|
||||
public <T> TypeAdapter<T> getAdapter(Class<T> type);
|
||||
|
||||
public <T> TypeAdapter<T> getAdapter(TypeToken<T> type);
|
||||
public <T> TypeAdapter<T> getAdapter(TypeToken<T> type);
|
||||
|
||||
public <T> TypeAdapter<T> getDelegateAdapter(TypeAdapterFactory skipPast, TypeToken<T> type);
|
||||
public <T> TypeAdapter<T> getDelegateAdapter(TypeAdapterFactory skipPast, TypeToken<T> type);
|
||||
|
||||
public String toJson(JsonElement jsonElement);
|
||||
public String toJson(JsonElement jsonElement);
|
||||
|
||||
public void toJson(JsonElement jsonElement, Appendable writer) throws JsonIOException;
|
||||
public void toJson(JsonElement jsonElement, Appendable writer) throws JsonIOException;
|
||||
|
||||
public void toJson(JsonElement jsonElement, JsonWriter writer) throws JsonIOException;
|
||||
public void toJson(JsonElement jsonElement, JsonWriter writer) throws JsonIOException;
|
||||
|
||||
/**
|
||||
* 对象序列化成Json
|
||||
*
|
||||
* @param src
|
||||
* 对象
|
||||
* @return 序列化后的对象
|
||||
*/
|
||||
public String toJson(Object src);
|
||||
/**
|
||||
* 对象序列化成Json
|
||||
*
|
||||
* @param src
|
||||
* 对象
|
||||
* @return 序列化后的对象
|
||||
*/
|
||||
public String toJson(Object src);
|
||||
|
||||
public void toJson(Object src, Appendable writer) throws JsonIOException;
|
||||
public void toJson(Object src, Appendable writer) throws JsonIOException;
|
||||
|
||||
public String toJson(Object src, Type typeOfSrc);
|
||||
public String toJson(Object src, Type typeOfSrc);
|
||||
|
||||
public void toJson(Object src, Type typeOfSrc, Appendable writer) throws JsonIOException;
|
||||
public void toJson(Object src, Type typeOfSrc, Appendable writer) throws JsonIOException;
|
||||
|
||||
public void toJson(Object src, Type typeOfSrc, JsonWriter writer) throws JsonIOException;
|
||||
public void toJson(Object src, Type typeOfSrc, JsonWriter writer) throws JsonIOException;
|
||||
|
||||
public JsonElement toJsonTree(Object src);
|
||||
public JsonElement toJsonTree(Object src);
|
||||
|
||||
public JsonElement toJsonTree(Object src, Type typeOfSrc);
|
||||
public JsonElement toJsonTree(Object src, Type typeOfSrc);
|
||||
|
||||
@Override
|
||||
public String toString();
|
||||
@Override
|
||||
public String toString();
|
||||
}
|
||||
|
@ -11,59 +11,59 @@ import java.util.Iterator;
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
public abstract interface JsonArray extends JsonElement, Iterable<JsonElement> {
|
||||
public void add(JsonElement element);
|
||||
public void add(JsonElement element);
|
||||
|
||||
public void addAll(JsonArray array);
|
||||
public void addAll(JsonArray array);
|
||||
|
||||
@Override
|
||||
public JsonArray deepCopy();
|
||||
@Override
|
||||
public JsonArray deepCopy();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o);
|
||||
@Override
|
||||
public boolean equals(Object o);
|
||||
|
||||
public JsonElement get(int i);
|
||||
public JsonElement get(int i);
|
||||
|
||||
@Override
|
||||
public BigDecimal getAsBigDecimal();
|
||||
@Override
|
||||
public BigDecimal getAsBigDecimal();
|
||||
|
||||
@Override
|
||||
public BigInteger getAsBigInteger();
|
||||
@Override
|
||||
public BigInteger getAsBigInteger();
|
||||
|
||||
@Override
|
||||
public boolean getAsBoolean();
|
||||
@Override
|
||||
public boolean getAsBoolean();
|
||||
|
||||
@Override
|
||||
public byte getAsByte();
|
||||
@Override
|
||||
public byte getAsByte();
|
||||
|
||||
@Override
|
||||
public char getAsCharacter();
|
||||
@Override
|
||||
public char getAsCharacter();
|
||||
|
||||
@Override
|
||||
public double getAsDouble();
|
||||
@Override
|
||||
public double getAsDouble();
|
||||
|
||||
@Override
|
||||
public float getAsFloat();
|
||||
@Override
|
||||
public float getAsFloat();
|
||||
|
||||
@Override
|
||||
public int getAsInt();
|
||||
@Override
|
||||
public int getAsInt();
|
||||
|
||||
@Override
|
||||
public long getAsLong();
|
||||
@Override
|
||||
public long getAsLong();
|
||||
|
||||
@Override
|
||||
public Number getAsNumber();
|
||||
@Override
|
||||
public Number getAsNumber();
|
||||
|
||||
@Override
|
||||
public short getAsShort();
|
||||
@Override
|
||||
public short getAsShort();
|
||||
|
||||
@Override
|
||||
public String getAsString();
|
||||
@Override
|
||||
public String getAsString();
|
||||
|
||||
@Override
|
||||
public int hashCode();
|
||||
@Override
|
||||
public int hashCode();
|
||||
|
||||
@Override
|
||||
public Iterator<JsonElement> iterator();
|
||||
@Override
|
||||
public Iterator<JsonElement> iterator();
|
||||
|
||||
public int size();
|
||||
public int size();
|
||||
}
|
||||
|
@ -9,48 +9,48 @@ import java.math.BigInteger;
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
public abstract interface JsonElement {
|
||||
public JsonElement deepCopy();
|
||||
public JsonElement deepCopy();
|
||||
|
||||
public BigDecimal getAsBigDecimal();
|
||||
public BigDecimal getAsBigDecimal();
|
||||
|
||||
public BigInteger getAsBigInteger();
|
||||
public BigInteger getAsBigInteger();
|
||||
|
||||
public boolean getAsBoolean();
|
||||
public boolean getAsBoolean();
|
||||
|
||||
public byte getAsByte();
|
||||
public byte getAsByte();
|
||||
|
||||
public char getAsCharacter();
|
||||
public char getAsCharacter();
|
||||
|
||||
public double getAsDouble();
|
||||
public double getAsDouble();
|
||||
|
||||
public float getAsFloat();
|
||||
public float getAsFloat();
|
||||
|
||||
public int getAsInt();
|
||||
public int getAsInt();
|
||||
|
||||
public JsonArray getAsJsonArray();
|
||||
public JsonArray getAsJsonArray();
|
||||
|
||||
public JsonNull getAsJsonNull();
|
||||
public JsonNull getAsJsonNull();
|
||||
|
||||
public JsonObject getAsJsonObject();
|
||||
public JsonObject getAsJsonObject();
|
||||
|
||||
public JsonPrimitive getAsJsonPrimitive();
|
||||
public JsonPrimitive getAsJsonPrimitive();
|
||||
|
||||
public long getAsLong();
|
||||
public long getAsLong();
|
||||
|
||||
public Number getAsNumber();
|
||||
public Number getAsNumber();
|
||||
|
||||
public short getAsShort();
|
||||
public short getAsShort();
|
||||
|
||||
public String getAsString();
|
||||
public String getAsString();
|
||||
|
||||
public boolean isJsonArray();
|
||||
public boolean isJsonArray();
|
||||
|
||||
public boolean isJsonNull();
|
||||
public boolean isJsonNull();
|
||||
|
||||
public boolean isJsonObject();
|
||||
public boolean isJsonObject();
|
||||
|
||||
public boolean isJsonPrimitive();
|
||||
public boolean isJsonPrimitive();
|
||||
|
||||
@Override
|
||||
public String toString();
|
||||
@Override
|
||||
public String toString();
|
||||
}
|
||||
|
@ -6,12 +6,12 @@ package cn.citycraft.GsonAgent.api;
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
public abstract interface JsonNull extends JsonElement {
|
||||
@Override
|
||||
public JsonNull deepCopy();
|
||||
@Override
|
||||
public JsonNull deepCopy();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other);
|
||||
@Override
|
||||
public boolean equals(Object other);
|
||||
|
||||
@Override
|
||||
public int hashCode();
|
||||
@Override
|
||||
public int hashCode();
|
||||
}
|
||||
|
@ -9,36 +9,36 @@ import java.util.Set;
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
public abstract interface JsonObject extends JsonElement {
|
||||
public void add(String property, JsonElement value);
|
||||
public void add(String property, JsonElement value);
|
||||
|
||||
public void addProperty(String property, Boolean value);
|
||||
public void addProperty(String property, Boolean value);
|
||||
|
||||
public void addProperty(String property, Character value);
|
||||
public void addProperty(String property, Character value);
|
||||
|
||||
public void addProperty(String property, Number value);
|
||||
public void addProperty(String property, Number value);
|
||||
|
||||
public void addProperty(String property, String value);
|
||||
public void addProperty(String property, String value);
|
||||
|
||||
@Override
|
||||
public JsonObject deepCopy();
|
||||
@Override
|
||||
public JsonObject deepCopy();
|
||||
|
||||
public Set<Map.Entry<String, JsonElement>> entrySet();
|
||||
public Set<Map.Entry<String, JsonElement>> entrySet();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o);
|
||||
@Override
|
||||
public boolean equals(Object o);
|
||||
|
||||
public JsonElement get(String memberName);
|
||||
public JsonElement get(String memberName);
|
||||
|
||||
public JsonArray getAsJsonArray(String memberName);
|
||||
public JsonArray getAsJsonArray(String memberName);
|
||||
|
||||
public JsonObject getAsJsonObject(String memberName);
|
||||
public JsonObject getAsJsonObject(String memberName);
|
||||
|
||||
public JsonPrimitive getAsJsonPrimitive(String memberName);
|
||||
public JsonPrimitive getAsJsonPrimitive(String memberName);
|
||||
|
||||
public boolean has(String memberName);
|
||||
public boolean has(String memberName);
|
||||
|
||||
@Override
|
||||
public int hashCode();
|
||||
@Override
|
||||
public int hashCode();
|
||||
|
||||
public JsonElement remove(String property);
|
||||
public JsonElement remove(String property);
|
||||
}
|
||||
|
@ -10,10 +10,10 @@ import cn.citycraft.GsonAgent.api.utils.HandleInterface;
|
||||
@SuppressWarnings("rawtypes")
|
||||
public abstract interface JsonParser extends HandleInterface {
|
||||
|
||||
public JsonElement parse(JsonReader json) throws JsonIOException, JsonSyntaxException;
|
||||
public JsonElement parse(JsonReader json) throws JsonIOException, JsonSyntaxException;
|
||||
|
||||
public JsonElement parse(Reader json) throws JsonIOException, JsonSyntaxException;
|
||||
public JsonElement parse(Reader json) throws JsonIOException, JsonSyntaxException;
|
||||
|
||||
public JsonElement parse(String json) throws JsonSyntaxException;
|
||||
public JsonElement parse(String json) throws JsonSyntaxException;
|
||||
|
||||
}
|
||||
|
@ -9,56 +9,56 @@ import java.math.BigInteger;
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
public abstract interface JsonPrimitive extends JsonElement {
|
||||
@Override
|
||||
public JsonPrimitive deepCopy();
|
||||
@Override
|
||||
public JsonPrimitive deepCopy();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj);
|
||||
@Override
|
||||
public boolean equals(Object obj);
|
||||
|
||||
@Override
|
||||
public BigDecimal getAsBigDecimal();
|
||||
@Override
|
||||
public BigDecimal getAsBigDecimal();
|
||||
|
||||
@Override
|
||||
public BigInteger getAsBigInteger();
|
||||
@Override
|
||||
public BigInteger getAsBigInteger();
|
||||
|
||||
@Override
|
||||
public boolean getAsBoolean();
|
||||
@Override
|
||||
public boolean getAsBoolean();
|
||||
|
||||
@Override
|
||||
public byte getAsByte();
|
||||
@Override
|
||||
public byte getAsByte();
|
||||
|
||||
@Override
|
||||
public char getAsCharacter();
|
||||
@Override
|
||||
public char getAsCharacter();
|
||||
|
||||
@Override
|
||||
public double getAsDouble();
|
||||
@Override
|
||||
public double getAsDouble();
|
||||
|
||||
@Override
|
||||
public float getAsFloat();
|
||||
@Override
|
||||
public float getAsFloat();
|
||||
|
||||
@Override
|
||||
public int getAsInt();
|
||||
@Override
|
||||
public int getAsInt();
|
||||
|
||||
@Override
|
||||
public long getAsLong();
|
||||
@Override
|
||||
public long getAsLong();
|
||||
|
||||
@Override
|
||||
public Number getAsNumber();
|
||||
@Override
|
||||
public Number getAsNumber();
|
||||
|
||||
@Override
|
||||
public short getAsShort();
|
||||
@Override
|
||||
public short getAsShort();
|
||||
|
||||
@Override
|
||||
public String getAsString();
|
||||
@Override
|
||||
public String getAsString();
|
||||
|
||||
@Override
|
||||
public int hashCode();
|
||||
@Override
|
||||
public int hashCode();
|
||||
|
||||
public boolean isBoolean();
|
||||
public boolean isBoolean();
|
||||
|
||||
public boolean isNumber();
|
||||
public boolean isNumber();
|
||||
|
||||
public boolean isString();
|
||||
public boolean isString();
|
||||
|
||||
void setValue(Object primitive);
|
||||
void setValue(Object primitive);
|
||||
}
|
||||
|
@ -11,21 +11,21 @@ import cn.citycraft.GsonAgent.api.utils.HandleInterface;
|
||||
@SuppressWarnings("rawtypes")
|
||||
public abstract interface TypeAdapter<T> extends HandleInterface {
|
||||
|
||||
public T fromJson(Reader in) throws IOException;
|
||||
public T fromJson(Reader in) throws IOException;
|
||||
|
||||
public T fromJson(String json) throws IOException;
|
||||
public T fromJson(String json) throws IOException;
|
||||
|
||||
public T fromJsonTree(JsonElement jsonTree);
|
||||
public T fromJsonTree(JsonElement jsonTree);
|
||||
|
||||
public TypeAdapter<T> nullSafe();
|
||||
public TypeAdapter<T> nullSafe();
|
||||
|
||||
public abstract T read(JsonReader paramJsonReader) throws IOException;
|
||||
public abstract T read(JsonReader paramJsonReader) throws IOException;
|
||||
|
||||
public String toJson(T value) throws IOException;
|
||||
public String toJson(T value) throws IOException;
|
||||
|
||||
public void toJson(Writer out, T value) throws IOException;
|
||||
public void toJson(Writer out, T value) throws IOException;
|
||||
|
||||
public JsonElement toJsonTree(T value);
|
||||
public JsonElement toJsonTree(T value);
|
||||
|
||||
public void write(JsonWriter paramJsonWriter, T paramT) throws IOException;
|
||||
public void write(JsonWriter paramJsonWriter, T paramT) throws IOException;
|
||||
}
|
||||
|
@ -4,5 +4,5 @@ import cn.citycraft.GsonAgent.api.reflect.TypeToken;
|
||||
|
||||
public abstract interface TypeAdapterFactory {
|
||||
|
||||
public abstract <T> TypeAdapter<T> create(Gson paramGson, TypeToken<T> paramTypeToken);
|
||||
public abstract <T> TypeAdapter<T> create(Gson paramGson, TypeToken<T> paramTypeToken);
|
||||
}
|
||||
|
@ -12,22 +12,22 @@ import cn.citycraft.GsonAgent.api.utils.HandleInterface;
|
||||
@SuppressWarnings("rawtypes")
|
||||
public abstract interface TypeAdapter<T> extends HandleInterface {
|
||||
|
||||
public T fromJson(Reader in) throws IOException;
|
||||
public T fromJson(Reader in) throws IOException;
|
||||
|
||||
public T fromJson(String json) throws IOException;
|
||||
public T fromJson(String json) throws IOException;
|
||||
|
||||
public T fromJsonTree(JsonElement jsonTree);
|
||||
public T fromJsonTree(JsonElement jsonTree);
|
||||
|
||||
public TypeAdapter<T> nullSafe();
|
||||
public TypeAdapter<T> nullSafe();
|
||||
|
||||
public abstract T read(JsonReader paramJsonReader) throws IOException;
|
||||
public abstract T read(JsonReader paramJsonReader) throws IOException;
|
||||
|
||||
public String toJson(T value) throws IOException;
|
||||
public String toJson(T value) throws IOException;
|
||||
|
||||
public void toJson(Writer out, T value) throws IOException;
|
||||
public void toJson(Writer out, T value) throws IOException;
|
||||
|
||||
public JsonElement toJsonTree(T value);
|
||||
public JsonElement toJsonTree(T value);
|
||||
|
||||
public void write(JsonWriter paramJsonWriter, T paramT) throws IOException;
|
||||
public void write(JsonWriter paramJsonWriter, T paramT) throws IOException;
|
||||
|
||||
}
|
||||
|
@ -4,5 +4,5 @@ import cn.citycraft.GsonAgent.api.Gson;
|
||||
import cn.citycraft.GsonAgent.api.reflect.TypeToken;
|
||||
|
||||
public abstract interface TypeAdapterFactory {
|
||||
public abstract <T> TypeAdapter<T> create(Gson paramGson, TypeToken<T> paramTypeToken);
|
||||
public abstract <T> TypeAdapter<T> create(Gson paramGson, TypeToken<T> paramTypeToken);
|
||||
}
|
||||
|
@ -7,74 +7,74 @@ import cn.citycraft.GsonAgent.GsonAgent;
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public class TypeToken<T> {
|
||||
|
||||
private final TypeTokenAbstract<T> internal;
|
||||
private final TypeTokenAbstract<T> internal;
|
||||
|
||||
public TypeToken() {
|
||||
if (GsonAgent.newVersion) {
|
||||
this.internal = new cn.citycraft.GsonAgent.normal.reflect.TypeTokenHandle<T>();
|
||||
} else {
|
||||
this.internal = new cn.citycraft.GsonAgent.nms.reflect.TypeTokenHandle<T>();
|
||||
}
|
||||
}
|
||||
public TypeToken() {
|
||||
if (GsonAgent.newVersion) {
|
||||
this.internal = new cn.citycraft.GsonAgent.normal.reflect.TypeTokenHandle<T>();
|
||||
} else {
|
||||
this.internal = new cn.citycraft.GsonAgent.nms.reflect.TypeTokenHandle<T>();
|
||||
}
|
||||
}
|
||||
|
||||
protected TypeToken(final TypeTokenAbstract<T> internal) {
|
||||
this.internal = internal;
|
||||
}
|
||||
protected TypeToken(final TypeTokenAbstract<T> internal) {
|
||||
this.internal = internal;
|
||||
}
|
||||
|
||||
public static <T> TypeToken<T> get(final Class<T> type) {
|
||||
if (GsonAgent.newVersion) {
|
||||
return new TypeToken(cn.citycraft.GsonAgent.normal.reflect.TypeTokenHandle.get(type));
|
||||
}
|
||||
return new TypeToken(cn.citycraft.GsonAgent.nms.reflect.TypeTokenHandle.get(type));
|
||||
}
|
||||
public static <T> TypeToken<T> get(final Class<T> type) {
|
||||
if (GsonAgent.newVersion) {
|
||||
return new TypeToken(cn.citycraft.GsonAgent.normal.reflect.TypeTokenHandle.get(type));
|
||||
}
|
||||
return new TypeToken(cn.citycraft.GsonAgent.nms.reflect.TypeTokenHandle.get(type));
|
||||
}
|
||||
|
||||
public static TypeToken<?> get(final Type type) {
|
||||
if (GsonAgent.newVersion) {
|
||||
return new TypeToken(cn.citycraft.GsonAgent.normal.reflect.TypeTokenHandle.get(type));
|
||||
}
|
||||
return new TypeToken(cn.citycraft.GsonAgent.nms.reflect.TypeTokenHandle.get(type));
|
||||
}
|
||||
public static TypeToken<?> get(final Type type) {
|
||||
if (GsonAgent.newVersion) {
|
||||
return new TypeToken(cn.citycraft.GsonAgent.normal.reflect.TypeTokenHandle.get(type));
|
||||
}
|
||||
return new TypeToken(cn.citycraft.GsonAgent.nms.reflect.TypeTokenHandle.get(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
return this.internal.equals(o);
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
return this.internal.equals(o);
|
||||
}
|
||||
|
||||
public Object getHandle() {
|
||||
return this.internal.getHandle();
|
||||
}
|
||||
public Object getHandle() {
|
||||
return this.internal.getHandle();
|
||||
}
|
||||
|
||||
public Class<? super T> getRawType() {
|
||||
return this.internal.getRawType();
|
||||
}
|
||||
public Class<? super T> getRawType() {
|
||||
return this.internal.getRawType();
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return this.internal.getType();
|
||||
}
|
||||
public Type getType() {
|
||||
return this.internal.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.internal.hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.internal.hashCode();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isAssignableFrom(final Class<?> cls) {
|
||||
return this.internal.isAssignableFrom(cls);
|
||||
}
|
||||
@Deprecated
|
||||
public boolean isAssignableFrom(final Class<?> cls) {
|
||||
return this.internal.isAssignableFrom(cls);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isAssignableFrom(final Type from) {
|
||||
return this.internal.isAssignableFrom(from);
|
||||
}
|
||||
@Deprecated
|
||||
public boolean isAssignableFrom(final Type from) {
|
||||
return this.internal.isAssignableFrom(from);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isAssignableFrom(final TypeToken<?> token) {
|
||||
return this.internal.isAssignableFrom(token);
|
||||
}
|
||||
@Deprecated
|
||||
public boolean isAssignableFrom(final TypeToken<?> token) {
|
||||
return this.internal.isAssignableFrom(token);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.internal.toString();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.internal.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,26 +7,26 @@ import cn.citycraft.GsonAgent.api.utils.HandleInterface;
|
||||
@SuppressWarnings("rawtypes")
|
||||
public abstract interface TypeTokenAbstract<T> extends HandleInterface {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o);
|
||||
@Override
|
||||
public boolean equals(Object o);
|
||||
|
||||
public Class<? super T> getRawType();
|
||||
public Class<? super T> getRawType();
|
||||
|
||||
public Type getType();
|
||||
public Type getType();
|
||||
|
||||
@Override
|
||||
public int hashCode();
|
||||
@Override
|
||||
public int hashCode();
|
||||
|
||||
@Deprecated
|
||||
public boolean isAssignableFrom(Class<?> cls);
|
||||
@Deprecated
|
||||
public boolean isAssignableFrom(Class<?> cls);
|
||||
|
||||
@Deprecated
|
||||
public boolean isAssignableFrom(Type from);
|
||||
@Deprecated
|
||||
public boolean isAssignableFrom(Type from);
|
||||
|
||||
@Deprecated
|
||||
public boolean isAssignableFrom(TypeToken<?> token);
|
||||
@Deprecated
|
||||
public boolean isAssignableFrom(TypeToken<?> token);
|
||||
|
||||
@Override
|
||||
public String toString();
|
||||
@Override
|
||||
public String toString();
|
||||
|
||||
}
|
||||
|
@ -4,41 +4,41 @@ import java.io.IOException;
|
||||
|
||||
public abstract interface JsonReader {
|
||||
|
||||
public void beginArray() throws IOException;
|
||||
public void beginArray() throws IOException;
|
||||
|
||||
public void beginObject() throws IOException;
|
||||
public void beginObject() throws IOException;
|
||||
|
||||
public void close() throws IOException;
|
||||
public void close() throws IOException;
|
||||
|
||||
public void endArray() throws IOException;
|
||||
public void endArray() throws IOException;
|
||||
|
||||
public void endObject() throws IOException;
|
||||
public void endObject() throws IOException;
|
||||
|
||||
public boolean hasNext() throws IOException;
|
||||
public boolean hasNext() throws IOException;
|
||||
|
||||
public boolean isLenient();
|
||||
public boolean isLenient();
|
||||
|
||||
public boolean nextBoolean() throws IOException;
|
||||
public boolean nextBoolean() throws IOException;
|
||||
|
||||
public double nextDouble() throws IOException;
|
||||
public double nextDouble() throws IOException;
|
||||
|
||||
public int nextInt() throws IOException;
|
||||
public int nextInt() throws IOException;
|
||||
|
||||
public long nextLong() throws IOException;
|
||||
public long nextLong() throws IOException;
|
||||
|
||||
public String nextName() throws IOException;
|
||||
public String nextName() throws IOException;
|
||||
|
||||
public void nextNull() throws IOException;
|
||||
public void nextNull() throws IOException;
|
||||
|
||||
public String nextString() throws IOException;
|
||||
public String nextString() throws IOException;
|
||||
|
||||
public JsonToken peek() throws IOException;
|
||||
public JsonToken peek() throws IOException;
|
||||
|
||||
public void setLenient(boolean lenient);
|
||||
public void setLenient(boolean lenient);
|
||||
|
||||
public void skipValue() throws IOException;
|
||||
public void skipValue() throws IOException;
|
||||
|
||||
@Override
|
||||
public String toString();
|
||||
@Override
|
||||
public String toString();
|
||||
|
||||
}
|
||||
|
@ -6,50 +6,94 @@ import java.io.IOException;
|
||||
|
||||
public abstract interface JsonWriter extends Closeable, Flushable {
|
||||
|
||||
public JsonWriter beginArray() throws IOException;
|
||||
/**
|
||||
* An array with no elements requires no separators or newlines before it is
|
||||
* closed.
|
||||
*/
|
||||
static final int EMPTY_ARRAY = 1;
|
||||
|
||||
public JsonWriter beginObject() throws IOException;
|
||||
/**
|
||||
* A array with at least one value requires a comma and newline before the
|
||||
* next element.
|
||||
*/
|
||||
static final int NONEMPTY_ARRAY = 2;
|
||||
|
||||
@Override
|
||||
public void close() throws IOException;
|
||||
/**
|
||||
* An object with no name/value pairs requires no separators or newlines
|
||||
* before it is closed.
|
||||
*/
|
||||
static final int EMPTY_OBJECT = 3;
|
||||
|
||||
public JsonWriter endArray() throws IOException;
|
||||
/**
|
||||
* An object whose most recent element is a key. The next element must be a
|
||||
* value.
|
||||
*/
|
||||
static final int DANGLING_NAME = 4;
|
||||
|
||||
public JsonWriter endObject() throws IOException;
|
||||
/**
|
||||
* An object with at least one name/value pair requires a comma and newline
|
||||
* before the next element.
|
||||
*/
|
||||
static final int NONEMPTY_OBJECT = 5;
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException;
|
||||
/**
|
||||
* No object or array has been started.
|
||||
*/
|
||||
static final int EMPTY_DOCUMENT = 6;
|
||||
|
||||
public boolean getSerializeNulls();
|
||||
/**
|
||||
* A document with at an array or object.
|
||||
*/
|
||||
static final int NONEMPTY_DOCUMENT = 7;
|
||||
|
||||
public boolean isHtmlSafe();
|
||||
/**
|
||||
* A document that's been closed and cannot be accessed.
|
||||
*/
|
||||
static final int CLOSED = 8;
|
||||
|
||||
public boolean isLenient();
|
||||
public JsonWriter beginArray() throws IOException;
|
||||
|
||||
public JsonWriter name(String name) throws IOException;
|
||||
public JsonWriter beginObject() throws IOException;
|
||||
|
||||
public JsonWriter nameWithoutQuotes(String name) throws IOException;
|
||||
@Override
|
||||
public void close() throws IOException;
|
||||
|
||||
public JsonWriter nullValue() throws IOException;
|
||||
public JsonWriter endArray() throws IOException;
|
||||
|
||||
public void setHtmlSafe(boolean htmlSafe);
|
||||
public JsonWriter endObject() throws IOException;
|
||||
|
||||
public void setIndent(String indent);
|
||||
@Override
|
||||
public void flush() throws IOException;
|
||||
|
||||
public void setLenient(boolean lenient);
|
||||
public boolean getSerializeNulls();
|
||||
|
||||
public void setSerializeNulls(boolean serializeNulls);
|
||||
public boolean isHtmlSafe();
|
||||
|
||||
public JsonWriter value(boolean value) throws IOException;
|
||||
public boolean isLenient();
|
||||
|
||||
public JsonWriter value(double value) throws IOException;
|
||||
public JsonWriter name(String name) throws IOException;
|
||||
|
||||
public JsonWriter value(long value) throws IOException;
|
||||
public JsonWriter nameWithoutQuotes(String name) throws IOException;
|
||||
|
||||
public JsonWriter value(Number value) throws IOException;
|
||||
public JsonWriter nullValue() throws IOException;
|
||||
|
||||
public JsonWriter value(String value) throws IOException;
|
||||
public void setHtmlSafe(boolean htmlSafe);
|
||||
|
||||
void string(String value) throws IOException;
|
||||
public void setIndent(String indent);
|
||||
|
||||
public void setLenient(boolean lenient);
|
||||
|
||||
public void setSerializeNulls(boolean serializeNulls);
|
||||
|
||||
public JsonWriter value(boolean value) throws IOException;
|
||||
|
||||
public JsonWriter value(double value) throws IOException;
|
||||
|
||||
public JsonWriter value(long value) throws IOException;
|
||||
|
||||
public JsonWriter value(Number value) throws IOException;
|
||||
|
||||
public JsonWriter value(String value) throws IOException;
|
||||
|
||||
void stringExtend(String value) throws IOException;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
package cn.citycraft.GsonAgent.api.utils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* Gson代理工具类(来自7老板)
|
||||
@ -13,42 +14,110 @@ import java.lang.reflect.Constructor;
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public class Utils {
|
||||
public static <T> T deepCopyObject(final T obj) {
|
||||
try {
|
||||
return (T) obj.getClass().getDeclaredMethod("deepCopy").invoke(obj);
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public static final String[] REPLACEMENT_CHARS;
|
||||
public static final String[] HTML_SAFE_REPLACEMENT_CHARS;
|
||||
|
||||
public static <T> T newInstance(final Class<T> clzz) {
|
||||
try {
|
||||
final Constructor<T> constructor = clzz.getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
return constructor.newInstance();
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
static {
|
||||
REPLACEMENT_CHARS = new String[128];
|
||||
for (int i = 0; i <= 0x1f; i++) {
|
||||
REPLACEMENT_CHARS[i] = String.format("\\u%04x", i);
|
||||
}
|
||||
REPLACEMENT_CHARS['"'] = "\\\"";
|
||||
REPLACEMENT_CHARS['\\'] = "\\\\";
|
||||
REPLACEMENT_CHARS['\t'] = "\\t";
|
||||
REPLACEMENT_CHARS['\b'] = "\\b";
|
||||
REPLACEMENT_CHARS['\n'] = "\\n";
|
||||
REPLACEMENT_CHARS['\r'] = "\\r";
|
||||
REPLACEMENT_CHARS['\f'] = "\\f";
|
||||
HTML_SAFE_REPLACEMENT_CHARS = REPLACEMENT_CHARS.clone();
|
||||
HTML_SAFE_REPLACEMENT_CHARS['<'] = "\\u003c";
|
||||
HTML_SAFE_REPLACEMENT_CHARS['>'] = "\\u003e";
|
||||
HTML_SAFE_REPLACEMENT_CHARS['&'] = "\\u0026";
|
||||
HTML_SAFE_REPLACEMENT_CHARS['='] = "\\u003d";
|
||||
HTML_SAFE_REPLACEMENT_CHARS['\''] = "\\u0027";
|
||||
}
|
||||
|
||||
public static <T> T newInstance(final Class<T> clzz, final Class[] types, final Object[] args) {
|
||||
if (args.length == 0 || types.length == 0) {
|
||||
return newInstance(clzz);
|
||||
}
|
||||
try {
|
||||
final Constructor<T> constructor = clzz.getDeclaredConstructor(types);
|
||||
constructor.setAccessible(true);
|
||||
return constructor.newInstance(args);
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public static <T> T deepCopyObject(final T obj) {
|
||||
try {
|
||||
return (T) obj.getClass().getDeclaredMethod("deepCopy").invoke(obj);
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T newInstance(final Class<T> clzz, final Object... args) {
|
||||
final Class[] argClasses = new Class[args.length];
|
||||
for (int i = 0; i < argClasses.length; i++) {
|
||||
argClasses[i] = args[i].getClass();
|
||||
}
|
||||
return newInstance(clzz, argClasses, args);
|
||||
}
|
||||
public static Field getDeclareField(final Class clzz, final String fieldName) throws Exception {
|
||||
final Field field = clzz.getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
}
|
||||
|
||||
public static Object invokeField(final Object object, final Field field) {
|
||||
try {
|
||||
return field.get(object);
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int[] invokeIntArrayField(final Object object, final Field field) {
|
||||
try {
|
||||
return (int[]) invokeField(object, field);
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int invokeIntField(final Object object, final Field field) {
|
||||
try {
|
||||
return ((Number) invokeField(object, field)).intValue();
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static String invokeStringField(final Object object, final Field field) {
|
||||
try {
|
||||
return (String) invokeField(object, field);
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void modifyField(final Object object, final Field field, final Object value) {
|
||||
try {
|
||||
field.set(object, value);
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T newInstance(final Class<T> clzz) {
|
||||
try {
|
||||
final Constructor<T> constructor = clzz.getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
return constructor.newInstance();
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T newInstance(final Class<T> clzz, final Class[] types, final Object[] args) {
|
||||
if (args.length == 0 || types.length == 0) {
|
||||
return newInstance(clzz);
|
||||
}
|
||||
try {
|
||||
final Constructor<T> constructor = clzz.getDeclaredConstructor(types);
|
||||
constructor.setAccessible(true);
|
||||
return constructor.newInstance(args);
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T newInstance(final Class<T> clzz, final Object... args) {
|
||||
final Class[] argClasses = new Class[args.length];
|
||||
for (int i = 0; i < argClasses.length; i++) {
|
||||
argClasses[i] = args[i].getClass();
|
||||
}
|
||||
return newInstance(clzz, argClasses, args);
|
||||
}
|
||||
}
|
||||
|
@ -22,114 +22,114 @@ import cn.citycraft.GsonAgent.nms.stream.JsonWriterHandle;
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public class GsonHandle implements Gson {
|
||||
private final net.minecraft.util.com.google.gson.Gson handle;
|
||||
private final net.minecraft.util.com.google.gson.Gson handle;
|
||||
|
||||
public GsonHandle() {
|
||||
handle = new net.minecraft.util.com.google.gson.Gson();
|
||||
}
|
||||
public GsonHandle() {
|
||||
handle = new net.minecraft.util.com.google.gson.Gson();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T fromJson(final cn.citycraft.GsonAgent.api.JsonElement json, final Class<T> classOfT) throws JsonSyntaxException {
|
||||
return getHandle().fromJson(((JsonElementHandle) json).getHandle(), classOfT);
|
||||
}
|
||||
@Override
|
||||
public <T> T fromJson(final cn.citycraft.GsonAgent.api.JsonElement json, final Class<T> classOfT) throws JsonSyntaxException {
|
||||
return getHandle().fromJson(((JsonElementHandle) json).getHandle(), classOfT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T fromJson(final cn.citycraft.GsonAgent.api.JsonElement json, final Type typeOfT) throws JsonSyntaxException {
|
||||
return getHandle().fromJson(((JsonElementHandle) json).getHandle(), typeOfT);
|
||||
}
|
||||
@Override
|
||||
public <T> T fromJson(final cn.citycraft.GsonAgent.api.JsonElement json, final Type typeOfT) throws JsonSyntaxException {
|
||||
return getHandle().fromJson(((JsonElementHandle) json).getHandle(), typeOfT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T fromJson(final cn.citycraft.GsonAgent.api.stream.JsonReader reader, final Type typeOfT) throws JsonIOException, JsonSyntaxException {
|
||||
return getHandle().fromJson(((JsonReaderHandle) reader).getHandle(), typeOfT);
|
||||
}
|
||||
@Override
|
||||
public <T> T fromJson(final cn.citycraft.GsonAgent.api.stream.JsonReader reader, final Type typeOfT) throws JsonIOException, JsonSyntaxException {
|
||||
return getHandle().fromJson(((JsonReaderHandle) reader).getHandle(), typeOfT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T fromJson(final Reader json, final Class<T> classOfT) throws JsonSyntaxException, JsonIOException {
|
||||
return getHandle().fromJson(json, classOfT);
|
||||
}
|
||||
@Override
|
||||
public <T> T fromJson(final Reader json, final Class<T> classOfT) throws JsonSyntaxException, JsonIOException {
|
||||
return getHandle().fromJson(json, classOfT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T fromJson(final Reader json, final Type typeOfT) throws JsonIOException, JsonSyntaxException {
|
||||
return getHandle().fromJson(json, typeOfT);
|
||||
}
|
||||
@Override
|
||||
public <T> T fromJson(final Reader json, final Type typeOfT) throws JsonIOException, JsonSyntaxException {
|
||||
return getHandle().fromJson(json, typeOfT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T fromJson(final String json, final Class<T> classOfT) throws JsonSyntaxException {
|
||||
return getHandle().fromJson(json, classOfT);
|
||||
}
|
||||
@Override
|
||||
public <T> T fromJson(final String json, final Class<T> classOfT) throws JsonSyntaxException {
|
||||
return getHandle().fromJson(json, classOfT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T fromJson(final String json, final Type typeOfT) throws JsonSyntaxException {
|
||||
return getHandle().fromJson(json, typeOfT);
|
||||
}
|
||||
@Override
|
||||
public <T> T fromJson(final String json, final Type typeOfT) throws JsonSyntaxException {
|
||||
return getHandle().fromJson(json, typeOfT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> TypeAdapterHandle<T> getAdapter(final Class<T> type) {
|
||||
return new TypeAdapterHandle(getHandle().getAdapter(type));
|
||||
}
|
||||
@Override
|
||||
public <T> TypeAdapterHandle<T> getAdapter(final Class<T> type) {
|
||||
return new TypeAdapterHandle(getHandle().getAdapter(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> TypeAdapterHandle<T> getAdapter(final cn.citycraft.GsonAgent.api.reflect.TypeToken<T> type) {
|
||||
return new TypeAdapterHandle(getHandle().getAdapter((net.minecraft.util.com.google.gson.reflect.TypeToken<T>) type.getHandle()));
|
||||
}
|
||||
@Override
|
||||
public <T> TypeAdapterHandle<T> getAdapter(final cn.citycraft.GsonAgent.api.reflect.TypeToken<T> type) {
|
||||
return new TypeAdapterHandle(getHandle().getAdapter((net.minecraft.util.com.google.gson.reflect.TypeToken<T>) type.getHandle()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> TypeAdapterHandle<T> getDelegateAdapter(final cn.citycraft.GsonAgent.api.TypeAdapterFactory skipPast, final cn.citycraft.GsonAgent.api.reflect.TypeToken<T> type) {
|
||||
return new TypeAdapterHandle(getHandle().getDelegateAdapter(((TypeAdapterFactoryHandle) skipPast).getHandle(), (net.minecraft.util.com.google.gson.reflect.TypeToken<T>) type.getHandle()));
|
||||
}
|
||||
@Override
|
||||
public <T> TypeAdapterHandle<T> getDelegateAdapter(final cn.citycraft.GsonAgent.api.TypeAdapterFactory skipPast, final cn.citycraft.GsonAgent.api.reflect.TypeToken<T> type) {
|
||||
return new TypeAdapterHandle(getHandle().getDelegateAdapter(((TypeAdapterFactoryHandle) skipPast).getHandle(), (net.minecraft.util.com.google.gson.reflect.TypeToken<T>) type.getHandle()));
|
||||
}
|
||||
|
||||
public net.minecraft.util.com.google.gson.Gson getHandle() {
|
||||
return handle;
|
||||
}
|
||||
public net.minecraft.util.com.google.gson.Gson getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJson(final cn.citycraft.GsonAgent.api.JsonElement jsonElement) {
|
||||
return getHandle().toJson(((JsonElementHandle) jsonElement).getHandle());
|
||||
}
|
||||
@Override
|
||||
public String toJson(final cn.citycraft.GsonAgent.api.JsonElement jsonElement) {
|
||||
return getHandle().toJson(((JsonElementHandle) jsonElement).getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(final cn.citycraft.GsonAgent.api.JsonElement jsonElement, final Appendable writer) throws JsonIOException {
|
||||
getHandle().toJson(((JsonElementHandle) jsonElement).getHandle(), writer);
|
||||
}
|
||||
@Override
|
||||
public void toJson(final cn.citycraft.GsonAgent.api.JsonElement jsonElement, final Appendable writer) throws JsonIOException {
|
||||
getHandle().toJson(((JsonElementHandle) jsonElement).getHandle(), writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(final cn.citycraft.GsonAgent.api.JsonElement jsonElement, final cn.citycraft.GsonAgent.api.stream.JsonWriter writer) throws JsonIOException {
|
||||
getHandle().toJson(((JsonElementHandle) jsonElement).getHandle(), ((JsonWriterHandle) writer).getHandle());
|
||||
}
|
||||
@Override
|
||||
public void toJson(final cn.citycraft.GsonAgent.api.JsonElement jsonElement, final cn.citycraft.GsonAgent.api.stream.JsonWriter writer) throws JsonIOException {
|
||||
getHandle().toJson(((JsonElementHandle) jsonElement).getHandle(), ((JsonWriterHandle) writer).getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJson(final Object src) {
|
||||
return getHandle().toJson(src);
|
||||
}
|
||||
@Override
|
||||
public String toJson(final Object src) {
|
||||
return getHandle().toJson(src);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(final Object src, final Appendable writer) throws JsonIOException {
|
||||
getHandle().toJson(src, writer);
|
||||
}
|
||||
@Override
|
||||
public void toJson(final Object src, final Appendable writer) throws JsonIOException {
|
||||
getHandle().toJson(src, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJson(final Object src, final Type typeOfSrc) {
|
||||
return getHandle().toJson(src, typeOfSrc);
|
||||
}
|
||||
@Override
|
||||
public String toJson(final Object src, final Type typeOfSrc) {
|
||||
return getHandle().toJson(src, typeOfSrc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(final Object src, final Type typeOfSrc, final Appendable writer) throws JsonIOException {
|
||||
getHandle().toJson(src, typeOfSrc, writer);
|
||||
}
|
||||
@Override
|
||||
public void toJson(final Object src, final Type typeOfSrc, final Appendable writer) throws JsonIOException {
|
||||
getHandle().toJson(src, typeOfSrc, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(final Object src, final Type typeOfSrc, final cn.citycraft.GsonAgent.api.stream.JsonWriter writer) throws JsonIOException {
|
||||
getHandle().toJson(src, typeOfSrc, ((JsonWriterHandle) writer).getHandle());
|
||||
}
|
||||
@Override
|
||||
public void toJson(final Object src, final Type typeOfSrc, final cn.citycraft.GsonAgent.api.stream.JsonWriter writer) throws JsonIOException {
|
||||
getHandle().toJson(src, typeOfSrc, ((JsonWriterHandle) writer).getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElementHandle toJsonTree(final Object src) {
|
||||
return new JsonElementHandle(getHandle().toJsonTree(src));
|
||||
}
|
||||
@Override
|
||||
public JsonElementHandle toJsonTree(final Object src) {
|
||||
return new JsonElementHandle(getHandle().toJsonTree(src));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElementHandle toJsonTree(final Object src, final Type typeOfSrc) {
|
||||
return new JsonElementHandle(getHandle().toJsonTree(src, typeOfSrc));
|
||||
}
|
||||
@Override
|
||||
public JsonElementHandle toJsonTree(final Object src, final Type typeOfSrc) {
|
||||
return new JsonElementHandle(getHandle().toJsonTree(src, typeOfSrc));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,143 +17,143 @@ import cn.citycraft.GsonAgent.api.utils.Utils;
|
||||
*/
|
||||
public class JsonArrayHandle extends JsonElementHandle implements JsonArray {
|
||||
|
||||
private static Field elementsField;
|
||||
private static Field elementsField;
|
||||
|
||||
static {
|
||||
try {
|
||||
elementsField = net.minecraft.util.com.google.gson.JsonArray.class.getDeclaredField("elements");
|
||||
elementsField.setAccessible(true);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
static {
|
||||
try {
|
||||
elementsField = net.minecraft.util.com.google.gson.JsonArray.class.getDeclaredField("elements");
|
||||
elementsField.setAccessible(true);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private final net.minecraft.util.com.google.gson.JsonArray handle;
|
||||
private final net.minecraft.util.com.google.gson.JsonArray handle;
|
||||
|
||||
private List<net.minecraft.util.com.google.gson.JsonElement> elements;
|
||||
private List<net.minecraft.util.com.google.gson.JsonElement> elements;
|
||||
|
||||
public JsonArrayHandle() {
|
||||
this(new net.minecraft.util.com.google.gson.JsonArray());
|
||||
}
|
||||
public JsonArrayHandle() {
|
||||
this(new net.minecraft.util.com.google.gson.JsonArray());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected JsonArrayHandle(final net.minecraft.util.com.google.gson.JsonArray handle) {
|
||||
this.handle = handle;
|
||||
try {
|
||||
elements = (List<net.minecraft.util.com.google.gson.JsonElement>) elementsField.get(this.handle);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
protected JsonArrayHandle(final net.minecraft.util.com.google.gson.JsonArray handle) {
|
||||
this.handle = handle;
|
||||
try {
|
||||
elements = (List<net.minecraft.util.com.google.gson.JsonElement>) elementsField.get(this.handle);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(final cn.citycraft.GsonAgent.api.JsonElement element) {
|
||||
handle.add(((JsonElementHandle) element).getHandle());
|
||||
}
|
||||
@Override
|
||||
public void add(final cn.citycraft.GsonAgent.api.JsonElement element) {
|
||||
handle.add(((JsonElementHandle) element).getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAll(final cn.citycraft.GsonAgent.api.JsonArray array) {
|
||||
handle.addAll(((JsonArrayHandle) array).handle);
|
||||
}
|
||||
@Override
|
||||
public void addAll(final cn.citycraft.GsonAgent.api.JsonArray array) {
|
||||
handle.addAll(((JsonArrayHandle) array).handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonArray deepCopy() {
|
||||
return new JsonArrayHandle(Utils.deepCopyObject(this.handle));
|
||||
}
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonArray deepCopy() {
|
||||
return new JsonArrayHandle(Utils.deepCopyObject(this.handle));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
return handle.equals(o);
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
return handle.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonElement get(final int i) {
|
||||
return new JsonElementHandle(handle.get(i));
|
||||
}
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonElement get(final int i) {
|
||||
return new JsonElementHandle(handle.get(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getAsBigDecimal() {
|
||||
return handle.getAsBigDecimal();
|
||||
}
|
||||
@Override
|
||||
public BigDecimal getAsBigDecimal() {
|
||||
return handle.getAsBigDecimal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger getAsBigInteger() {
|
||||
return handle.getAsBigInteger();
|
||||
}
|
||||
@Override
|
||||
public BigInteger getAsBigInteger() {
|
||||
return handle.getAsBigInteger();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return handle.getAsBoolean();
|
||||
}
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return handle.getAsBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getAsByte() {
|
||||
return handle.getAsByte();
|
||||
}
|
||||
@Override
|
||||
public byte getAsByte() {
|
||||
return handle.getAsByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getAsCharacter() {
|
||||
return handle.getAsCharacter();
|
||||
}
|
||||
@Override
|
||||
public char getAsCharacter() {
|
||||
return handle.getAsCharacter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAsDouble() {
|
||||
return handle.getAsDouble();
|
||||
}
|
||||
@Override
|
||||
public double getAsDouble() {
|
||||
return handle.getAsDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAsFloat() {
|
||||
return handle.getAsFloat();
|
||||
}
|
||||
@Override
|
||||
public float getAsFloat() {
|
||||
return handle.getAsFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
return handle.getAsInt();
|
||||
}
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
return handle.getAsInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAsLong() {
|
||||
return handle.getAsLong();
|
||||
}
|
||||
@Override
|
||||
public long getAsLong() {
|
||||
return handle.getAsLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAsNumber() {
|
||||
return handle.getAsNumber();
|
||||
}
|
||||
@Override
|
||||
public Number getAsNumber() {
|
||||
return handle.getAsNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getAsShort() {
|
||||
return handle.getAsShort();
|
||||
}
|
||||
@Override
|
||||
public short getAsShort() {
|
||||
return handle.getAsShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString() {
|
||||
return handle.getAsString();
|
||||
}
|
||||
@Override
|
||||
public String getAsString() {
|
||||
return handle.getAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<cn.citycraft.GsonAgent.api.JsonElement> iterator() {
|
||||
try {
|
||||
final List<cn.citycraft.GsonAgent.api.JsonElement> result = new ArrayList<>();
|
||||
final Iterator<net.minecraft.util.com.google.gson.JsonElement> iterator = this.elements.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
result.add(new JsonElementHandle(iterator.next()));
|
||||
}
|
||||
return result.iterator();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Iterator<cn.citycraft.GsonAgent.api.JsonElement> iterator() {
|
||||
try {
|
||||
final List<cn.citycraft.GsonAgent.api.JsonElement> result = new ArrayList<>();
|
||||
final Iterator<net.minecraft.util.com.google.gson.JsonElement> iterator = this.elements.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
result.add(new JsonElementHandle(iterator.next()));
|
||||
}
|
||||
return result.iterator();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return handle.size();
|
||||
}
|
||||
@Override
|
||||
public int size() {
|
||||
return handle.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,127 +17,127 @@ import cn.citycraft.GsonAgent.api.utils.Utils;
|
||||
*/
|
||||
public class JsonElementHandle implements JsonElement {
|
||||
|
||||
private net.minecraft.util.com.google.gson.JsonElement handle;
|
||||
private net.minecraft.util.com.google.gson.JsonElement handle;
|
||||
|
||||
public JsonElementHandle() {
|
||||
}
|
||||
public JsonElementHandle() {
|
||||
}
|
||||
|
||||
public JsonElementHandle(final net.minecraft.util.com.google.gson.JsonElement handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
public JsonElementHandle(final net.minecraft.util.com.google.gson.JsonElement handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonElement deepCopy() {
|
||||
return new JsonElementHandle(Utils.deepCopyObject(this.getHandle()));
|
||||
}
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonElement deepCopy() {
|
||||
return new JsonElementHandle(Utils.deepCopyObject(this.getHandle()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getAsBigDecimal() {
|
||||
return getHandle().getAsBigDecimal();
|
||||
}
|
||||
@Override
|
||||
public BigDecimal getAsBigDecimal() {
|
||||
return getHandle().getAsBigDecimal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger getAsBigInteger() {
|
||||
return getHandle().getAsBigInteger();
|
||||
}
|
||||
@Override
|
||||
public BigInteger getAsBigInteger() {
|
||||
return getHandle().getAsBigInteger();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return getHandle().getAsBoolean();
|
||||
}
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return getHandle().getAsBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getAsByte() {
|
||||
return getHandle().getAsByte();
|
||||
}
|
||||
@Override
|
||||
public byte getAsByte() {
|
||||
return getHandle().getAsByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getAsCharacter() {
|
||||
return getHandle().getAsCharacter();
|
||||
}
|
||||
@Override
|
||||
public char getAsCharacter() {
|
||||
return getHandle().getAsCharacter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAsDouble() {
|
||||
return getHandle().getAsDouble();
|
||||
}
|
||||
@Override
|
||||
public double getAsDouble() {
|
||||
return getHandle().getAsDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAsFloat() {
|
||||
return getHandle().getAsFloat();
|
||||
}
|
||||
@Override
|
||||
public float getAsFloat() {
|
||||
return getHandle().getAsFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
return getHandle().getAsInt();
|
||||
}
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
return getHandle().getAsInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonArrayHandle getAsJsonArray() {
|
||||
return new JsonArrayHandle(getHandle().getAsJsonArray());
|
||||
}
|
||||
@Override
|
||||
public JsonArrayHandle getAsJsonArray() {
|
||||
return new JsonArrayHandle(getHandle().getAsJsonArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNullHandle getAsJsonNull() {
|
||||
return new JsonNullHandle(getHandle().getAsJsonNull());
|
||||
}
|
||||
@Override
|
||||
public JsonNullHandle getAsJsonNull() {
|
||||
return new JsonNullHandle(getHandle().getAsJsonNull());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObjectHandle getAsJsonObject() {
|
||||
return new JsonObjectHandle(getHandle().getAsJsonObject());
|
||||
}
|
||||
@Override
|
||||
public JsonObjectHandle getAsJsonObject() {
|
||||
return new JsonObjectHandle(getHandle().getAsJsonObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonPrimitiveHandle getAsJsonPrimitive() {
|
||||
return new JsonPrimitiveHandle(getHandle().getAsJsonPrimitive());
|
||||
}
|
||||
@Override
|
||||
public JsonPrimitiveHandle getAsJsonPrimitive() {
|
||||
return new JsonPrimitiveHandle(getHandle().getAsJsonPrimitive());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAsLong() {
|
||||
return getHandle().getAsLong();
|
||||
}
|
||||
@Override
|
||||
public long getAsLong() {
|
||||
return getHandle().getAsLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAsNumber() {
|
||||
return getHandle().getAsNumber();
|
||||
}
|
||||
@Override
|
||||
public Number getAsNumber() {
|
||||
return getHandle().getAsNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getAsShort() {
|
||||
return getHandle().getAsShort();
|
||||
}
|
||||
@Override
|
||||
public short getAsShort() {
|
||||
return getHandle().getAsShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString() {
|
||||
return getHandle().getAsString();
|
||||
}
|
||||
@Override
|
||||
public String getAsString() {
|
||||
return getHandle().getAsString();
|
||||
}
|
||||
|
||||
public net.minecraft.util.com.google.gson.JsonElement getHandle() {
|
||||
return handle;
|
||||
}
|
||||
public net.minecraft.util.com.google.gson.JsonElement getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJsonArray() {
|
||||
return getHandle().isJsonArray();
|
||||
}
|
||||
@Override
|
||||
public boolean isJsonArray() {
|
||||
return getHandle().isJsonArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJsonNull() {
|
||||
return getHandle().isJsonNull();
|
||||
}
|
||||
@Override
|
||||
public boolean isJsonNull() {
|
||||
return getHandle().isJsonNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJsonObject() {
|
||||
return getHandle().isJsonObject();
|
||||
}
|
||||
@Override
|
||||
public boolean isJsonObject() {
|
||||
return getHandle().isJsonObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJsonPrimitive() {
|
||||
return getHandle().isJsonPrimitive();
|
||||
}
|
||||
@Override
|
||||
public boolean isJsonPrimitive() {
|
||||
return getHandle().isJsonPrimitive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getHandle().toString();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return getHandle().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,28 +9,28 @@ import cn.citycraft.GsonAgent.api.JsonNull;
|
||||
*/
|
||||
public class JsonNullHandle extends JsonElementHandle implements JsonNull {
|
||||
|
||||
private final net.minecraft.util.com.google.gson.JsonNull handle;
|
||||
private final net.minecraft.util.com.google.gson.JsonNull handle;
|
||||
|
||||
public JsonNullHandle() {
|
||||
this(net.minecraft.util.com.google.gson.JsonNull.INSTANCE);
|
||||
}
|
||||
public JsonNullHandle() {
|
||||
this(net.minecraft.util.com.google.gson.JsonNull.INSTANCE);
|
||||
}
|
||||
|
||||
protected JsonNullHandle(final net.minecraft.util.com.google.gson.JsonNull handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
protected JsonNullHandle(final net.minecraft.util.com.google.gson.JsonNull handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonNull deepCopy() {
|
||||
return new JsonNullHandle();
|
||||
}
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonNull deepCopy() {
|
||||
return new JsonNullHandle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object other) {
|
||||
return handle.equals(other);
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final Object other) {
|
||||
return handle.equals(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
}
|
||||
|
@ -16,116 +16,116 @@ import net.minecraft.util.com.google.gson.internal.LinkedTreeMap;
|
||||
*/
|
||||
public class JsonObjectHandle extends JsonElementHandle implements JsonObject {
|
||||
|
||||
private static Field membersField;
|
||||
private static Field membersField;
|
||||
|
||||
static {
|
||||
try {
|
||||
membersField = net.minecraft.util.com.google.gson.JsonObject.class.getDeclaredField("members");
|
||||
membersField.setAccessible(true);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
static {
|
||||
try {
|
||||
membersField = net.minecraft.util.com.google.gson.JsonObject.class.getDeclaredField("members");
|
||||
membersField.setAccessible(true);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private final net.minecraft.util.com.google.gson.JsonObject handle;
|
||||
private final net.minecraft.util.com.google.gson.JsonObject handle;
|
||||
|
||||
private AbstractMap<String, net.minecraft.util.com.google.gson.JsonElement> members;
|
||||
private AbstractMap<String, net.minecraft.util.com.google.gson.JsonElement> members;
|
||||
|
||||
public JsonObjectHandle() {
|
||||
this(new net.minecraft.util.com.google.gson.JsonObject());
|
||||
}
|
||||
public JsonObjectHandle() {
|
||||
this(new net.minecraft.util.com.google.gson.JsonObject());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected JsonObjectHandle(final net.minecraft.util.com.google.gson.JsonObject handle) {
|
||||
this.handle = handle;
|
||||
try {
|
||||
members = (AbstractMap<String, net.minecraft.util.com.google.gson.JsonElement>) membersField.get(this.handle);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
protected JsonObjectHandle(final net.minecraft.util.com.google.gson.JsonObject handle) {
|
||||
this.handle = handle;
|
||||
try {
|
||||
members = (AbstractMap<String, net.minecraft.util.com.google.gson.JsonElement>) membersField.get(this.handle);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(final String property, final cn.citycraft.GsonAgent.api.JsonElement value) {
|
||||
handle.add(property, ((JsonElementHandle) value).getHandle());
|
||||
}
|
||||
@Override
|
||||
public void add(final String property, final cn.citycraft.GsonAgent.api.JsonElement value) {
|
||||
handle.add(property, ((JsonElementHandle) value).getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProperty(final String property, final Boolean value) {
|
||||
handle.addProperty(property, value);
|
||||
}
|
||||
@Override
|
||||
public void addProperty(final String property, final Boolean value) {
|
||||
handle.addProperty(property, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProperty(final String property, final Character value) {
|
||||
handle.addProperty(property, value);
|
||||
}
|
||||
@Override
|
||||
public void addProperty(final String property, final Character value) {
|
||||
handle.addProperty(property, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProperty(final String property, final Number value) {
|
||||
handle.addProperty(property, value);
|
||||
}
|
||||
@Override
|
||||
public void addProperty(final String property, final Number value) {
|
||||
handle.addProperty(property, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProperty(final String property, final String value) {
|
||||
handle.addProperty(property, value);
|
||||
}
|
||||
@Override
|
||||
public void addProperty(final String property, final String value) {
|
||||
handle.addProperty(property, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonObject deepCopy() {
|
||||
return new JsonObjectHandle(Utils.deepCopyObject(this.handle));
|
||||
}
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonObject deepCopy() {
|
||||
return new JsonObjectHandle(Utils.deepCopyObject(this.handle));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Map.Entry<String, cn.citycraft.GsonAgent.api.JsonElement>> entrySet() {
|
||||
try {
|
||||
final Map<String, cn.citycraft.GsonAgent.api.JsonElement> result = new LinkedTreeMap<>();
|
||||
for (final Map.Entry<String, net.minecraft.util.com.google.gson.JsonElement> entry : members.entrySet()) {
|
||||
result.put(entry.getKey(), new JsonElementHandle(entry.getValue()));
|
||||
}
|
||||
return result.entrySet();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Set<Map.Entry<String, cn.citycraft.GsonAgent.api.JsonElement>> entrySet() {
|
||||
try {
|
||||
final Map<String, cn.citycraft.GsonAgent.api.JsonElement> result = new LinkedTreeMap<>();
|
||||
for (final Map.Entry<String, net.minecraft.util.com.google.gson.JsonElement> entry : members.entrySet()) {
|
||||
result.put(entry.getKey(), new JsonElementHandle(entry.getValue()));
|
||||
}
|
||||
return result.entrySet();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
return handle.equals(o);
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
return handle.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElementHandle get(final String memberName) {
|
||||
return new JsonElementHandle(handle.get(memberName));
|
||||
}
|
||||
@Override
|
||||
public JsonElementHandle get(final String memberName) {
|
||||
return new JsonElementHandle(handle.get(memberName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonArrayHandle getAsJsonArray(final String memberName) {
|
||||
return new JsonArrayHandle(handle.getAsJsonArray(memberName));
|
||||
}
|
||||
@Override
|
||||
public JsonArrayHandle getAsJsonArray(final String memberName) {
|
||||
return new JsonArrayHandle(handle.getAsJsonArray(memberName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObjectHandle getAsJsonObject(final String memberName) {
|
||||
return new JsonObjectHandle(handle.getAsJsonObject(memberName));
|
||||
}
|
||||
@Override
|
||||
public JsonObjectHandle getAsJsonObject(final String memberName) {
|
||||
return new JsonObjectHandle(handle.getAsJsonObject(memberName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonPrimitiveHandle getAsJsonPrimitive(final String memberName) {
|
||||
return new JsonPrimitiveHandle(handle.getAsJsonPrimitive(memberName));
|
||||
}
|
||||
@Override
|
||||
public JsonPrimitiveHandle getAsJsonPrimitive(final String memberName) {
|
||||
return new JsonPrimitiveHandle(handle.getAsJsonPrimitive(memberName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(final String memberName) {
|
||||
return handle.has(memberName);
|
||||
}
|
||||
@Override
|
||||
public boolean has(final String memberName) {
|
||||
return handle.has(memberName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElementHandle remove(final String property) {
|
||||
return new JsonElementHandle(handle.remove(property));
|
||||
}
|
||||
@Override
|
||||
public JsonElementHandle remove(final String property) {
|
||||
return new JsonElementHandle(handle.remove(property));
|
||||
}
|
||||
}
|
||||
|
@ -8,34 +8,34 @@ import cn.citycraft.GsonAgent.nms.stream.JsonReaderHandle;
|
||||
|
||||
public class JsonParserHandle implements cn.citycraft.GsonAgent.api.JsonParser {
|
||||
|
||||
public net.minecraft.util.com.google.gson.JsonParser handle;
|
||||
public net.minecraft.util.com.google.gson.JsonParser handle;
|
||||
|
||||
public JsonParserHandle() {
|
||||
handle = new net.minecraft.util.com.google.gson.JsonParser();
|
||||
}
|
||||
public JsonParserHandle() {
|
||||
handle = new net.minecraft.util.com.google.gson.JsonParser();
|
||||
}
|
||||
|
||||
protected JsonParserHandle(final net.minecraft.util.com.google.gson.JsonParser handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
protected JsonParserHandle(final net.minecraft.util.com.google.gson.JsonParser handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.util.com.google.gson.JsonParser getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
@Override
|
||||
public net.minecraft.util.com.google.gson.JsonParser getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElementHandle parse(final cn.citycraft.GsonAgent.api.stream.JsonReader json) throws JsonIOException, JsonSyntaxException {
|
||||
return new JsonElementHandle(getHandle().parse(((JsonReaderHandle) json).getHandle()));
|
||||
}
|
||||
@Override
|
||||
public JsonElementHandle parse(final cn.citycraft.GsonAgent.api.stream.JsonReader json) throws JsonIOException, JsonSyntaxException {
|
||||
return new JsonElementHandle(getHandle().parse(((JsonReaderHandle) json).getHandle()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElementHandle parse(final Reader json) throws JsonIOException, JsonSyntaxException {
|
||||
return new JsonElementHandle(getHandle().parse(json));
|
||||
}
|
||||
@Override
|
||||
public JsonElementHandle parse(final Reader json) throws JsonIOException, JsonSyntaxException {
|
||||
return new JsonElementHandle(getHandle().parse(json));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElementHandle parse(final String json) throws JsonSyntaxException {
|
||||
return new JsonElementHandle(getHandle().parse(json));
|
||||
}
|
||||
@Override
|
||||
public JsonElementHandle parse(final String json) throws JsonSyntaxException {
|
||||
return new JsonElementHandle(getHandle().parse(json));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,139 +16,139 @@ import cn.citycraft.GsonAgent.api.utils.Utils;
|
||||
*/
|
||||
public class JsonPrimitiveHandle extends JsonElementHandle implements JsonPrimitive {
|
||||
|
||||
private final net.minecraft.util.com.google.gson.JsonPrimitive handle;
|
||||
private final net.minecraft.util.com.google.gson.JsonPrimitive handle;
|
||||
|
||||
public JsonPrimitiveHandle(final Boolean bool) {
|
||||
this(new net.minecraft.util.com.google.gson.JsonPrimitive(bool));
|
||||
setValue(bool);
|
||||
}
|
||||
public JsonPrimitiveHandle(final Boolean bool) {
|
||||
this(new net.minecraft.util.com.google.gson.JsonPrimitive(bool));
|
||||
setValue(bool);
|
||||
}
|
||||
|
||||
public JsonPrimitiveHandle(final Character c) {
|
||||
this(new net.minecraft.util.com.google.gson.JsonPrimitive(c));
|
||||
setValue(c);
|
||||
}
|
||||
public JsonPrimitiveHandle(final Character c) {
|
||||
this(new net.minecraft.util.com.google.gson.JsonPrimitive(c));
|
||||
setValue(c);
|
||||
}
|
||||
|
||||
public JsonPrimitiveHandle(final Number number) {
|
||||
this(new net.minecraft.util.com.google.gson.JsonPrimitive(number));
|
||||
setValue(number);
|
||||
}
|
||||
public JsonPrimitiveHandle(final Number number) {
|
||||
this(new net.minecraft.util.com.google.gson.JsonPrimitive(number));
|
||||
setValue(number);
|
||||
}
|
||||
|
||||
public JsonPrimitiveHandle(final String string) {
|
||||
this(new net.minecraft.util.com.google.gson.JsonPrimitive(string));
|
||||
setValue(string);
|
||||
}
|
||||
public JsonPrimitiveHandle(final String string) {
|
||||
this(new net.minecraft.util.com.google.gson.JsonPrimitive(string));
|
||||
setValue(string);
|
||||
}
|
||||
|
||||
protected JsonPrimitiveHandle(final net.minecraft.util.com.google.gson.JsonPrimitive handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
protected JsonPrimitiveHandle(final net.minecraft.util.com.google.gson.JsonPrimitive handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonPrimitive deepCopy() {
|
||||
return new JsonPrimitiveHandle(Utils.deepCopyObject(this.handle));
|
||||
}
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonPrimitive deepCopy() {
|
||||
return new JsonPrimitiveHandle(Utils.deepCopyObject(this.handle));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return handle.equals(obj);
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return handle.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getAsBigDecimal() {
|
||||
return handle.getAsBigDecimal();
|
||||
}
|
||||
@Override
|
||||
public BigDecimal getAsBigDecimal() {
|
||||
return handle.getAsBigDecimal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger getAsBigInteger() {
|
||||
return handle.getAsBigInteger();
|
||||
}
|
||||
@Override
|
||||
public BigInteger getAsBigInteger() {
|
||||
return handle.getAsBigInteger();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return handle.getAsBoolean();
|
||||
}
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return handle.getAsBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getAsByte() {
|
||||
return handle.getAsByte();
|
||||
}
|
||||
@Override
|
||||
public byte getAsByte() {
|
||||
return handle.getAsByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getAsCharacter() {
|
||||
return handle.getAsCharacter();
|
||||
}
|
||||
@Override
|
||||
public char getAsCharacter() {
|
||||
return handle.getAsCharacter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAsDouble() {
|
||||
return handle.getAsDouble();
|
||||
}
|
||||
@Override
|
||||
public double getAsDouble() {
|
||||
return handle.getAsDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAsFloat() {
|
||||
return handle.getAsFloat();
|
||||
}
|
||||
@Override
|
||||
public float getAsFloat() {
|
||||
return handle.getAsFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
return handle.getAsInt();
|
||||
}
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
return handle.getAsInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonArrayHandle getAsJsonArray() {
|
||||
return new JsonArrayHandle(handle.getAsJsonArray());
|
||||
}
|
||||
@Override
|
||||
public JsonArrayHandle getAsJsonArray() {
|
||||
return new JsonArrayHandle(handle.getAsJsonArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObjectHandle getAsJsonObject() {
|
||||
return new JsonObjectHandle(handle.getAsJsonObject());
|
||||
}
|
||||
@Override
|
||||
public JsonObjectHandle getAsJsonObject() {
|
||||
return new JsonObjectHandle(handle.getAsJsonObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAsLong() {
|
||||
return handle.getAsLong();
|
||||
}
|
||||
@Override
|
||||
public long getAsLong() {
|
||||
return handle.getAsLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAsNumber() {
|
||||
return handle.getAsNumber();
|
||||
}
|
||||
@Override
|
||||
public Number getAsNumber() {
|
||||
return handle.getAsNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getAsShort() {
|
||||
return handle.getAsShort();
|
||||
}
|
||||
@Override
|
||||
public short getAsShort() {
|
||||
return handle.getAsShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString() {
|
||||
return handle.getAsString();
|
||||
}
|
||||
@Override
|
||||
public String getAsString() {
|
||||
return handle.getAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBoolean() {
|
||||
return handle.isBoolean();
|
||||
}
|
||||
@Override
|
||||
public boolean isBoolean() {
|
||||
return handle.isBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNumber() {
|
||||
return handle.isNumber();
|
||||
}
|
||||
@Override
|
||||
public boolean isNumber() {
|
||||
return handle.isNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isString() {
|
||||
return handle.isString();
|
||||
}
|
||||
@Override
|
||||
public boolean isString() {
|
||||
return handle.isString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setValue(final Object primitive) {
|
||||
try {
|
||||
handle.getClass().getDeclaredMethod("setValue", Object.class).invoke(handle, primitive);
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public final void setValue(final Object primitive) {
|
||||
try {
|
||||
handle.getClass().getDeclaredMethod("setValue", Object.class).invoke(handle, primitive);
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,24 +9,24 @@ import net.minecraft.util.com.google.gson.reflect.TypeToken;
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public class TypeAdapterFactoryHandle implements cn.citycraft.GsonAgent.api.TypeAdapterFactory, net.minecraft.util.com.google.gson.TypeAdapterFactory {
|
||||
|
||||
private final TypeAdapterFactory handle;
|
||||
private final TypeAdapterFactory handle;
|
||||
|
||||
protected TypeAdapterFactoryHandle(final TypeAdapterFactory handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
protected TypeAdapterFactoryHandle(final TypeAdapterFactory handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> TypeAdapterHandle<T> create(final cn.citycraft.GsonAgent.api.Gson paramGson, final cn.citycraft.GsonAgent.api.reflect.TypeToken<T> paramTypeToken) {
|
||||
return new TypeAdapterHandle(this.create(((GsonHandle) paramGson).getHandle(), (TypeToken<T>) paramTypeToken.getHandle()));
|
||||
}
|
||||
@Override
|
||||
public <T> TypeAdapterHandle<T> create(final cn.citycraft.GsonAgent.api.Gson paramGson, final cn.citycraft.GsonAgent.api.reflect.TypeToken<T> paramTypeToken) {
|
||||
return new TypeAdapterHandle(this.create(((GsonHandle) paramGson).getHandle(), (TypeToken<T>) paramTypeToken.getHandle()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> TypeAdapter<T> create(final Gson paramGson, final TypeToken<T> paramTypeToken) {
|
||||
return this.getHandle().create(paramGson, paramTypeToken);
|
||||
}
|
||||
@Override
|
||||
public <T> TypeAdapter<T> create(final Gson paramGson, final TypeToken<T> paramTypeToken) {
|
||||
return this.getHandle().create(paramGson, paramTypeToken);
|
||||
}
|
||||
|
||||
public TypeAdapterFactory getHandle() {
|
||||
return handle;
|
||||
}
|
||||
public TypeAdapterFactory getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,65 +9,65 @@ import net.minecraft.util.com.google.gson.reflect.TypeToken;
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public class TypeTokenHandle<T> implements cn.citycraft.GsonAgent.api.reflect.TypeTokenAbstract<T> {
|
||||
|
||||
private TypeToken<T> handle;
|
||||
private TypeToken<T> handle;
|
||||
|
||||
public TypeTokenHandle() {
|
||||
try {
|
||||
handle = new TypeToken<T>() {
|
||||
};
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public TypeTokenHandle() {
|
||||
try {
|
||||
handle = new TypeToken<T>() {
|
||||
};
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public TypeTokenHandle(final Type type) {
|
||||
try {
|
||||
handle = Utils.newInstance(TypeToken.class, Type.class, type);
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public TypeTokenHandle(final Type type) {
|
||||
try {
|
||||
handle = Utils.newInstance(TypeToken.class, Type.class, type);
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected TypeTokenHandle(final TypeToken<T> handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
protected TypeTokenHandle(final TypeToken<T> handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
public static <T> TypeTokenAbstract<T> get(final Class<T> type) {
|
||||
return new TypeTokenHandle(TypeToken.get(type));
|
||||
}
|
||||
public static <T> TypeTokenAbstract<T> get(final Class<T> type) {
|
||||
return new TypeTokenHandle(TypeToken.get(type));
|
||||
}
|
||||
|
||||
public static TypeTokenAbstract<?> get(final Type type) {
|
||||
return new TypeTokenHandle(TypeToken.get(type));
|
||||
}
|
||||
public static TypeTokenAbstract<?> get(final Type type) {
|
||||
return new TypeTokenHandle(TypeToken.get(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeToken<T> getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
@Override
|
||||
public TypeToken<T> getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? super T> getRawType() {
|
||||
return getHandle().getRawType();
|
||||
}
|
||||
@Override
|
||||
public Class<? super T> getRawType() {
|
||||
return getHandle().getRawType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return getHandle().getType();
|
||||
}
|
||||
@Override
|
||||
public Type getType() {
|
||||
return getHandle().getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssignableFrom(final Class<?> cls) {
|
||||
return getHandle().isAssignableFrom(cls);
|
||||
}
|
||||
@Override
|
||||
public boolean isAssignableFrom(final Class<?> cls) {
|
||||
return getHandle().isAssignableFrom(cls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssignableFrom(final cn.citycraft.GsonAgent.api.reflect.TypeToken<?> token) {
|
||||
return getHandle().isAssignableFrom((TypeToken<?>) token.getHandle());
|
||||
}
|
||||
@Override
|
||||
public boolean isAssignableFrom(final cn.citycraft.GsonAgent.api.reflect.TypeToken<?> token) {
|
||||
return getHandle().isAssignableFrom((TypeToken<?>) token.getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssignableFrom(final Type from) {
|
||||
return getHandle().isAssignableFrom(from);
|
||||
}
|
||||
@Override
|
||||
public boolean isAssignableFrom(final Type from) {
|
||||
return getHandle().isAssignableFrom(from);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,108 +8,108 @@ import net.minecraft.util.com.google.gson.stream.JsonReader;
|
||||
|
||||
public class JsonReaderHandle implements cn.citycraft.GsonAgent.api.stream.JsonReader {
|
||||
|
||||
private final JsonReader handle;
|
||||
private final JsonReader handle;
|
||||
|
||||
public JsonReaderHandle(final Reader in) {
|
||||
this(new JsonReader(in));
|
||||
}
|
||||
public JsonReaderHandle(final Reader in) {
|
||||
this(new JsonReader(in));
|
||||
}
|
||||
|
||||
protected JsonReaderHandle(final JsonReader handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
protected JsonReaderHandle(final JsonReader handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginArray() throws IOException {
|
||||
getHandle().beginArray();
|
||||
}
|
||||
@Override
|
||||
public void beginArray() throws IOException {
|
||||
getHandle().beginArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginObject() throws IOException {
|
||||
getHandle().beginObject();
|
||||
}
|
||||
@Override
|
||||
public void beginObject() throws IOException {
|
||||
getHandle().beginObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
getHandle().close();
|
||||
}
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
getHandle().close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endArray() throws IOException {
|
||||
getHandle().endArray();
|
||||
}
|
||||
@Override
|
||||
public void endArray() throws IOException {
|
||||
getHandle().endArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endObject() throws IOException {
|
||||
getHandle().endObject();
|
||||
}
|
||||
@Override
|
||||
public void endObject() throws IOException {
|
||||
getHandle().endObject();
|
||||
}
|
||||
|
||||
public JsonReader getHandle() {
|
||||
return handle;
|
||||
}
|
||||
public JsonReader getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() throws IOException {
|
||||
return getHandle().hasNext();
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() throws IOException {
|
||||
return getHandle().hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLenient() {
|
||||
return getHandle().isLenient();
|
||||
}
|
||||
@Override
|
||||
public boolean isLenient() {
|
||||
return getHandle().isLenient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextBoolean() throws IOException {
|
||||
return getHandle().nextBoolean();
|
||||
}
|
||||
@Override
|
||||
public boolean nextBoolean() throws IOException {
|
||||
return getHandle().nextBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextDouble() throws IOException {
|
||||
return getHandle().nextDouble();
|
||||
}
|
||||
@Override
|
||||
public double nextDouble() throws IOException {
|
||||
return getHandle().nextDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextInt() throws IOException {
|
||||
return getHandle().nextInt();
|
||||
}
|
||||
@Override
|
||||
public int nextInt() throws IOException {
|
||||
return getHandle().nextInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long nextLong() throws IOException {
|
||||
return getHandle().nextLong();
|
||||
}
|
||||
@Override
|
||||
public long nextLong() throws IOException {
|
||||
return getHandle().nextLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nextName() throws IOException {
|
||||
return getHandle().nextName();
|
||||
}
|
||||
@Override
|
||||
public String nextName() throws IOException {
|
||||
return getHandle().nextName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nextNull() throws IOException {
|
||||
getHandle().nextNull();
|
||||
}
|
||||
@Override
|
||||
public void nextNull() throws IOException {
|
||||
getHandle().nextNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nextString() throws IOException {
|
||||
return getHandle().nextString();
|
||||
}
|
||||
@Override
|
||||
public String nextString() throws IOException {
|
||||
return getHandle().nextString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonToken peek() throws IOException {
|
||||
return JsonToken.getByName(getHandle().peek().name());
|
||||
}
|
||||
@Override
|
||||
public JsonToken peek() throws IOException {
|
||||
return JsonToken.getByName(getHandle().peek().name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLenient(final boolean lenient) {
|
||||
getHandle().setLenient(lenient);
|
||||
}
|
||||
@Override
|
||||
public void setLenient(final boolean lenient) {
|
||||
getHandle().setLenient(lenient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void skipValue() throws IOException {
|
||||
getHandle().skipValue();
|
||||
}
|
||||
@Override
|
||||
public void skipValue() throws IOException {
|
||||
getHandle().skipValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getHandle().toString();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return getHandle().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,205 +4,483 @@ import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import cn.citycraft.GsonAgent.api.utils.Utils;
|
||||
import net.minecraft.util.com.google.gson.stream.JsonWriter;
|
||||
|
||||
public class JsonWriterHandle implements cn.citycraft.GsonAgent.api.stream.JsonWriter {
|
||||
public class JsonWriterHandle extends JsonWriter implements cn.citycraft.GsonAgent.api.stream.JsonWriter {
|
||||
/*
|
||||
* From RFC 4627, "All Unicode characters may be placed within the
|
||||
* quotation marks except for the characters that must be escaped:
|
||||
* quotation mark, reverse solidus, and the control characters
|
||||
* (U+0000 through U+001F)."
|
||||
*
|
||||
* We also escape '\u2028' and '\u2029', which JavaScript interprets as
|
||||
* newline characters. This prevents eval() from failing with a syntax
|
||||
* error. http://code.google.com/p/google-gson/issues/detail?id=341
|
||||
*/
|
||||
private static Field stackField, stackSizeField, indentField, separatorField;
|
||||
|
||||
private static String[] REPLACEMENT_CHARS;
|
||||
static {
|
||||
final Class<JsonWriter> clzz = JsonWriter.class;
|
||||
try {
|
||||
stackField = Utils.getDeclareField(clzz, "stack");
|
||||
stackSizeField = Utils.getDeclareField(clzz, "stackSize");
|
||||
indentField = Utils.getDeclareField(clzz, "indent");
|
||||
separatorField = Utils.getDeclareField(clzz, "separator");
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static String[] HTML_SAFE_REPLACEMENT_CHARS;
|
||||
/**
|
||||
* The output data, containing at most one top-level array or object.
|
||||
*/
|
||||
private final Writer out;
|
||||
private String deferredName;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field field = JsonWriter.class.getDeclaredField("REPLACEMENT_CHARS");
|
||||
field.setAccessible(true);
|
||||
REPLACEMENT_CHARS = (String[]) field.get(null);
|
||||
field = JsonWriter.class.getDeclaredField("HTML_SAFE_REPLACEMENT_CHARS");
|
||||
field.setAccessible(true);
|
||||
HTML_SAFE_REPLACEMENT_CHARS = (String[]) field.get(null);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private boolean withoutQuotes = false;
|
||||
|
||||
private final JsonWriter handle;
|
||||
/**
|
||||
* Creates a new instance that writes a JSON-encoded stream to {@code out}.
|
||||
* For best performance, ensure {@link Writer} is buffered; wrapping in
|
||||
* {@link java.io.BufferedWriter BufferedWriter} if necessary.
|
||||
*
|
||||
* @param out
|
||||
*/
|
||||
public JsonWriterHandle(final Writer out) {
|
||||
super(out);
|
||||
this.out = out;
|
||||
}
|
||||
|
||||
private Writer out;
|
||||
/**
|
||||
* Begins encoding a new array. Each call to this method must be paired with
|
||||
* a call to {@link #endArray}.
|
||||
*
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle beginArray() throws IOException {
|
||||
writeDeferredName();
|
||||
return open(EMPTY_ARRAY, "[");
|
||||
}
|
||||
|
||||
private boolean withoutQuotes = false;
|
||||
/**
|
||||
* Begins encoding a new object. Each call to this method must be paired
|
||||
* with a call to {@link #endObject}.
|
||||
*
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle beginObject() throws IOException {
|
||||
writeDeferredName();
|
||||
return open(EMPTY_OBJECT, "{");
|
||||
}
|
||||
|
||||
public JsonWriterHandle(final Writer out) {
|
||||
this(new JsonWriter(out));
|
||||
this.out = out;
|
||||
}
|
||||
/**
|
||||
* Flushes and closes this writer and the underlying {@link Writer}.
|
||||
*
|
||||
* @throws IOException
|
||||
* if the JSON document is incomplete.
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
out.close();
|
||||
final int size = this.getStackSize();
|
||||
if (size > 1 || size == 1 && this.getStack()[size - 1] != NONEMPTY_DOCUMENT) {
|
||||
throw new IOException("Incomplete document");
|
||||
}
|
||||
this.setStackSize(0);
|
||||
}
|
||||
|
||||
protected JsonWriterHandle(final JsonWriter handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
/**
|
||||
* Ends encoding the current array.
|
||||
*
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle endArray() throws IOException {
|
||||
return close(EMPTY_ARRAY, NONEMPTY_ARRAY, "]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle beginArray() throws IOException {
|
||||
getHandle().beginArray();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Ends encoding the current object.
|
||||
*
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle endObject() throws IOException {
|
||||
return close(EMPTY_OBJECT, NONEMPTY_OBJECT, "}");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle beginObject() throws IOException {
|
||||
getHandle().beginObject();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Ensures all buffered data is written to the underlying {@link Writer} and
|
||||
* flushes that writer.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
if (this.getStackSize() == 0) {
|
||||
throw new IllegalStateException("JsonWriterHandle is closed.");
|
||||
}
|
||||
out.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
getHandle().close();
|
||||
}
|
||||
public JsonWriterHandle getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle endArray() throws IOException {
|
||||
getHandle().endArray();
|
||||
return this;
|
||||
}
|
||||
public String getIndent() {
|
||||
return Utils.invokeStringField(this, indentField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle endObject() throws IOException {
|
||||
getHandle().endObject();
|
||||
return this;
|
||||
}
|
||||
public String getSeparator() {
|
||||
return Utils.invokeStringField(this, separatorField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
getHandle().flush();
|
||||
}
|
||||
public int[] getStack() {
|
||||
return Utils.invokeIntArrayField(this, stackField);
|
||||
}
|
||||
|
||||
public JsonWriter getHandle() {
|
||||
return handle;
|
||||
}
|
||||
public int getStackSize() {
|
||||
return Utils.invokeIntField(this, stackSizeField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSerializeNulls() {
|
||||
return getHandle().getSerializeNulls();
|
||||
}
|
||||
/**
|
||||
* Encodes the property name.
|
||||
*
|
||||
* @param name
|
||||
* the name of the forthcoming value. May not be null.
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle name(final String name) throws IOException {
|
||||
if (name == null) {
|
||||
throw new NullPointerException("name == null");
|
||||
}
|
||||
if (deferredName != null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
if (this.getStackSize() == 0) {
|
||||
throw new IllegalStateException("JsonWriterHandle is closed.");
|
||||
}
|
||||
deferredName = name;
|
||||
withoutQuotes = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHtmlSafe() {
|
||||
return getHandle().isHtmlSafe();
|
||||
}
|
||||
@Override
|
||||
public JsonWriterHandle nameWithoutQuotes(final String name) throws IOException {
|
||||
this.name(name);
|
||||
withoutQuotes = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLenient() {
|
||||
return getHandle().isLenient();
|
||||
}
|
||||
/**
|
||||
* Encodes {@code null}.
|
||||
*
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle nullValue() throws IOException {
|
||||
if (deferredName != null) {
|
||||
if (this.getSerializeNulls()) {
|
||||
writeDeferredName();
|
||||
} else {
|
||||
deferredName = null;
|
||||
return this; // skip the name and the value
|
||||
}
|
||||
}
|
||||
beforeValue(false);
|
||||
out.write("null");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle name(final String name) throws IOException {
|
||||
getHandle().name(name);
|
||||
withoutQuotes = false;
|
||||
return this;
|
||||
}
|
||||
public void setSeparator(final String separator) {
|
||||
Utils.modifyField(this, separatorField, separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle nameWithoutQuotes(final String name) throws IOException {
|
||||
getHandle().name(name);
|
||||
withoutQuotes = true;
|
||||
return this;
|
||||
}
|
||||
public void setStack(final int index, final int value) {
|
||||
final int[] newStack = this.getStack();
|
||||
newStack[index] = value;
|
||||
this.setStack(newStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle nullValue() throws IOException {
|
||||
getHandle().nullValue();
|
||||
return this;
|
||||
}
|
||||
public void setStack(final int[] stack) {
|
||||
Utils.modifyField(this, stackField, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHtmlSafe(final boolean htmlSafe) {
|
||||
getHandle().setHtmlSafe(htmlSafe);
|
||||
}
|
||||
public void setStackSize(final int stackSize) {
|
||||
Utils.modifyField(this, stackSizeField, stackSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIndent(final String indent) {
|
||||
getHandle().setIndent(indent);
|
||||
}
|
||||
@Override
|
||||
public void stringExtend(final String value) throws IOException {
|
||||
final String[] replacements = this.isHtmlSafe() ? Utils.HTML_SAFE_REPLACEMENT_CHARS : Utils.REPLACEMENT_CHARS;
|
||||
if (!this.withoutQuotes) {
|
||||
this.out.write("\"");
|
||||
}
|
||||
int last = 0;
|
||||
final int length = value.length();
|
||||
for (int i = 0; i < length; i++) {
|
||||
final char c = value.charAt(i);
|
||||
String replacement;
|
||||
if (c < 128) {
|
||||
replacement = replacements[c];
|
||||
if (replacement == null) {
|
||||
continue;
|
||||
}
|
||||
} else if (c == '\u2028') {
|
||||
replacement = "\\u2028";
|
||||
} else if (c == '\u2029') {
|
||||
replacement = "\\u2029";
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
if (last < i) {
|
||||
out.write(value, last, i - last);
|
||||
}
|
||||
out.write(replacement);
|
||||
last = i + 1;
|
||||
}
|
||||
if (last < length) {
|
||||
out.write(value, last, length - last);
|
||||
}
|
||||
if (!this.withoutQuotes) {
|
||||
this.out.write("\"");
|
||||
}
|
||||
withoutQuotes = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLenient(final boolean lenient) {
|
||||
getHandle().setLenient(lenient);
|
||||
}
|
||||
/**
|
||||
* Encodes {@code value}.
|
||||
*
|
||||
* @param value
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle value(final boolean value) throws IOException {
|
||||
writeDeferredName();
|
||||
beforeValue(false);
|
||||
out.write(value ? "true" : "false");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSerializeNulls(final boolean serializeNulls) {
|
||||
getHandle().setSerializeNulls(serializeNulls);
|
||||
}
|
||||
/**
|
||||
* Encodes {@code value}.
|
||||
*
|
||||
* @param value
|
||||
* a finite value. May not be {@link Double#isNaN() NaNs} or
|
||||
* {@link Double#isInfinite() infinities}.
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle value(final double value) throws IOException {
|
||||
if (Double.isNaN(value) || Double.isInfinite(value)) {
|
||||
throw new IllegalArgumentException("Numeric values must be finite, but was " + value);
|
||||
}
|
||||
writeDeferredName();
|
||||
beforeValue(false);
|
||||
out.append(Double.toString(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void string(final String value) throws IOException {
|
||||
final String[] replacements = getHandle().isHtmlSafe() ? HTML_SAFE_REPLACEMENT_CHARS : REPLACEMENT_CHARS;
|
||||
if (!this.withoutQuotes) {
|
||||
this.out.write("\"");
|
||||
}
|
||||
int last = 0;
|
||||
final int length = value.length();
|
||||
for (int i = 0; i < length; i++) {
|
||||
final char c = value.charAt(i);
|
||||
String replacement;
|
||||
if (c < '') {
|
||||
replacement = replacements[c];
|
||||
if (replacement == null) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (c == '
') {
|
||||
replacement = "\\u2028";
|
||||
} else {
|
||||
if (c != '
') {
|
||||
continue;
|
||||
}
|
||||
replacement = "\\u2029";
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Encodes {@code value}.
|
||||
*
|
||||
* @param value
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle value(final long value) throws IOException {
|
||||
writeDeferredName();
|
||||
beforeValue(false);
|
||||
out.write(Long.toString(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
if (last < i) {
|
||||
this.out.write(value, last, i - last);
|
||||
}
|
||||
this.out.write(replacement);
|
||||
last = i + 1;
|
||||
}
|
||||
if (last < length) {
|
||||
this.out.write(value, last, length - last);
|
||||
}
|
||||
if (!this.withoutQuotes) {
|
||||
this.out.write("\"");
|
||||
}
|
||||
withoutQuotes = false;
|
||||
}
|
||||
/**
|
||||
* Encodes {@code value}.
|
||||
*
|
||||
* @param value
|
||||
* a finite value. May not be {@link Double#isNaN() NaNs} or
|
||||
* {@link Double#isInfinite() infinities}.
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle value(final Number value) throws IOException {
|
||||
if (value == null) {
|
||||
return nullValue();
|
||||
}
|
||||
writeDeferredName();
|
||||
final String string = value.toString();
|
||||
if (!this.isLenient() && (string.equals("-Infinity") || string.equals("Infinity") || string.equals("NaN"))) {
|
||||
throw new IllegalArgumentException("Numeric values must be finite, but was " + value);
|
||||
}
|
||||
beforeValue(false);
|
||||
out.append(string);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle value(final boolean value) throws IOException {
|
||||
getHandle().value(value);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Encodes {@code value}.
|
||||
*
|
||||
* @param value
|
||||
* the literal string value, or null to encode a null literal.
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle value(final String value) throws IOException {
|
||||
if (value == null) {
|
||||
return nullValue();
|
||||
}
|
||||
writeDeferredName();
|
||||
beforeValue(false);
|
||||
stringExtend(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle value(final double value) throws IOException {
|
||||
getHandle().value(value);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Inserts any necessary separators and whitespace before a name. Also
|
||||
* adjusts the stack to expect the name's value.
|
||||
*/
|
||||
private void beforeName() throws IOException {
|
||||
final int context = peek();
|
||||
if (context == NONEMPTY_OBJECT) { // first in object
|
||||
out.write(',');
|
||||
} else if (context != EMPTY_OBJECT) { // not in an object!
|
||||
throw new IllegalStateException("Nesting problem.");
|
||||
}
|
||||
newline();
|
||||
replaceTop(DANGLING_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle value(final long value) throws IOException {
|
||||
getHandle().value(value);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Inserts any necessary separators and whitespace before a literal value,
|
||||
* inline array, or inline object. Also adjusts the stack to expect either a
|
||||
* closing bracket or another element.
|
||||
*
|
||||
* @param root
|
||||
* true if the value is a new array or object, the two values
|
||||
* permitted as top-level elements.
|
||||
*/
|
||||
@SuppressWarnings("fallthrough")
|
||||
private void beforeValue(final boolean root) throws IOException {
|
||||
switch (peek()) {
|
||||
case NONEMPTY_DOCUMENT:
|
||||
if (!this.isLenient()) {
|
||||
throw new IllegalStateException("JSON must have only one top-level value.");
|
||||
}
|
||||
// fall-through
|
||||
case EMPTY_DOCUMENT: // first in document
|
||||
if (!this.isLenient() && !root) {
|
||||
throw new IllegalStateException("JSON must start with an array or an object.");
|
||||
}
|
||||
replaceTop(NONEMPTY_DOCUMENT);
|
||||
break;
|
||||
case EMPTY_ARRAY: // first in array
|
||||
replaceTop(NONEMPTY_ARRAY);
|
||||
newline();
|
||||
break;
|
||||
case NONEMPTY_ARRAY: // another in array
|
||||
out.append(',');
|
||||
newline();
|
||||
break;
|
||||
case DANGLING_NAME: // value for name
|
||||
out.append(this.getSeparator());
|
||||
replaceTop(NONEMPTY_OBJECT);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Nesting problem.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle value(final Number value) throws IOException {
|
||||
getHandle().value(value);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Closes the current scope by appending any necessary whitespace and the
|
||||
* given bracket.
|
||||
*/
|
||||
private JsonWriterHandle close(final int empty, final int nonempty, final String closeBracket) throws IOException {
|
||||
final int context = peek();
|
||||
if (context != nonempty && context != empty) {
|
||||
throw new IllegalStateException("Nesting problem.");
|
||||
}
|
||||
if (deferredName != null) {
|
||||
throw new IllegalStateException("Dangling name: " + deferredName);
|
||||
}
|
||||
this.setStackSize(this.getStackSize() - 1);
|
||||
if (context == nonempty) {
|
||||
newline();
|
||||
}
|
||||
out.write(closeBracket);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle value(final String value) throws IOException {
|
||||
getHandle().value(value);
|
||||
return this;
|
||||
}
|
||||
private void newline() throws IOException {
|
||||
if (this.getIndent() == null) {
|
||||
return;
|
||||
}
|
||||
out.write("\n");
|
||||
for (int i = 1, size = this.getStackSize(); i < size; i++) {
|
||||
out.write(this.getIndent());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters a new scope by appending any necessary whitespace and the given
|
||||
* bracket.
|
||||
*/
|
||||
private JsonWriterHandle open(final int empty, final String openBracket) throws IOException {
|
||||
beforeValue(true);
|
||||
push(empty);
|
||||
out.write(openBracket);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value on the top of the stack.
|
||||
*/
|
||||
private int peek() {
|
||||
if (this.getStackSize() == 0) {
|
||||
throw new IllegalStateException("JsonWriterHandle is closed.");
|
||||
}
|
||||
return this.getStack()[this.getStackSize() - 1];
|
||||
}
|
||||
|
||||
private void push(final int newTop) {
|
||||
int[] stacks = this.getStack();
|
||||
if (this.getStackSize() == stacks.length) {
|
||||
final int[] newStack = new int[stacks.length * 2];
|
||||
System.arraycopy(stacks, 0, newStack, 0, stacks.length);
|
||||
stacks = newStack;
|
||||
this.setStack(stacks);
|
||||
}
|
||||
this.setStack(this.getStackSize(), newTop);
|
||||
this.setStackSize(this.getStackSize() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the value on the top of the stack with the given value.
|
||||
*/
|
||||
private void replaceTop(final int topOfStack) {
|
||||
this.getStack()[this.getStackSize() - 1] = topOfStack;
|
||||
}
|
||||
|
||||
private void writeDeferredName() throws IOException {
|
||||
if (deferredName != null) {
|
||||
beforeName();
|
||||
stringExtend(deferredName);
|
||||
deferredName = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,109 +20,109 @@ import cn.citycraft.GsonAgent.normal.stream.JsonWriterHandle;
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public class GsonHandle implements Gson {
|
||||
final com.google.gson.Gson handle = new com.google.gson.Gson();
|
||||
final com.google.gson.Gson handle = new com.google.gson.Gson();
|
||||
|
||||
@Override
|
||||
public <T> T fromJson(final cn.citycraft.GsonAgent.api.JsonElement json, final Class<T> classOfT) throws JsonSyntaxException {
|
||||
return getHandle().fromJson(((JsonElementHandle) json).getHandle(), classOfT);
|
||||
}
|
||||
@Override
|
||||
public <T> T fromJson(final cn.citycraft.GsonAgent.api.JsonElement json, final Class<T> classOfT) throws JsonSyntaxException {
|
||||
return getHandle().fromJson(((JsonElementHandle) json).getHandle(), classOfT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T fromJson(final cn.citycraft.GsonAgent.api.JsonElement json, final Type typeOfT) throws JsonSyntaxException {
|
||||
return getHandle().fromJson(((JsonElementHandle) json).getHandle(), typeOfT);
|
||||
}
|
||||
@Override
|
||||
public <T> T fromJson(final cn.citycraft.GsonAgent.api.JsonElement json, final Type typeOfT) throws JsonSyntaxException {
|
||||
return getHandle().fromJson(((JsonElementHandle) json).getHandle(), typeOfT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T fromJson(final cn.citycraft.GsonAgent.api.stream.JsonReader reader, final Type typeOfT) throws JsonIOException, JsonSyntaxException {
|
||||
return getHandle().fromJson(((JsonReaderHandle) reader).getHandle(), typeOfT);
|
||||
}
|
||||
@Override
|
||||
public <T> T fromJson(final cn.citycraft.GsonAgent.api.stream.JsonReader reader, final Type typeOfT) throws JsonIOException, JsonSyntaxException {
|
||||
return getHandle().fromJson(((JsonReaderHandle) reader).getHandle(), typeOfT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T fromJson(final Reader json, final Class<T> classOfT) throws JsonSyntaxException, JsonIOException {
|
||||
return getHandle().fromJson(json, classOfT);
|
||||
}
|
||||
@Override
|
||||
public <T> T fromJson(final Reader json, final Class<T> classOfT) throws JsonSyntaxException, JsonIOException {
|
||||
return getHandle().fromJson(json, classOfT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T fromJson(final Reader json, final Type typeOfT) throws JsonIOException, JsonSyntaxException {
|
||||
return getHandle().fromJson(json, typeOfT);
|
||||
}
|
||||
@Override
|
||||
public <T> T fromJson(final Reader json, final Type typeOfT) throws JsonIOException, JsonSyntaxException {
|
||||
return getHandle().fromJson(json, typeOfT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T fromJson(final String json, final Class<T> classOfT) throws JsonSyntaxException {
|
||||
return getHandle().fromJson(json, classOfT);
|
||||
}
|
||||
@Override
|
||||
public <T> T fromJson(final String json, final Class<T> classOfT) throws JsonSyntaxException {
|
||||
return getHandle().fromJson(json, classOfT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T fromJson(final String json, final Type typeOfT) throws JsonSyntaxException {
|
||||
return getHandle().fromJson(json, typeOfT);
|
||||
}
|
||||
@Override
|
||||
public <T> T fromJson(final String json, final Type typeOfT) throws JsonSyntaxException {
|
||||
return getHandle().fromJson(json, typeOfT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> TypeAdapterHandle<T> getAdapter(final Class<T> type) {
|
||||
return new TypeAdapterHandle(getHandle().getAdapter(type));
|
||||
}
|
||||
@Override
|
||||
public <T> TypeAdapterHandle<T> getAdapter(final Class<T> type) {
|
||||
return new TypeAdapterHandle(getHandle().getAdapter(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> TypeAdapterHandle<T> getAdapter(final cn.citycraft.GsonAgent.api.reflect.TypeToken<T> type) {
|
||||
return new TypeAdapterHandle(getHandle().getAdapter((com.google.gson.reflect.TypeToken<T>) type.getHandle()));
|
||||
}
|
||||
@Override
|
||||
public <T> TypeAdapterHandle<T> getAdapter(final cn.citycraft.GsonAgent.api.reflect.TypeToken<T> type) {
|
||||
return new TypeAdapterHandle(getHandle().getAdapter((com.google.gson.reflect.TypeToken<T>) type.getHandle()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> TypeAdapterHandle<T> getDelegateAdapter(final cn.citycraft.GsonAgent.api.TypeAdapterFactory skipPast, final cn.citycraft.GsonAgent.api.reflect.TypeToken<T> type) {
|
||||
return new TypeAdapterHandle(getHandle().getDelegateAdapter(((TypeAdapterFactoryHandle) skipPast).getHandle(), (com.google.gson.reflect.TypeToken<T>) type.getHandle()));
|
||||
}
|
||||
@Override
|
||||
public <T> TypeAdapterHandle<T> getDelegateAdapter(final cn.citycraft.GsonAgent.api.TypeAdapterFactory skipPast, final cn.citycraft.GsonAgent.api.reflect.TypeToken<T> type) {
|
||||
return new TypeAdapterHandle(getHandle().getDelegateAdapter(((TypeAdapterFactoryHandle) skipPast).getHandle(), (com.google.gson.reflect.TypeToken<T>) type.getHandle()));
|
||||
}
|
||||
|
||||
public com.google.gson.Gson getHandle() {
|
||||
return handle;
|
||||
}
|
||||
public com.google.gson.Gson getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJson(final cn.citycraft.GsonAgent.api.JsonElement jsonElement) {
|
||||
return getHandle().toJson(((JsonElementHandle) jsonElement).getHandle());
|
||||
}
|
||||
@Override
|
||||
public String toJson(final cn.citycraft.GsonAgent.api.JsonElement jsonElement) {
|
||||
return getHandle().toJson(((JsonElementHandle) jsonElement).getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(final cn.citycraft.GsonAgent.api.JsonElement jsonElement, final Appendable writer) throws JsonIOException {
|
||||
getHandle().toJson(((JsonElementHandle) jsonElement).getHandle(), writer);
|
||||
}
|
||||
@Override
|
||||
public void toJson(final cn.citycraft.GsonAgent.api.JsonElement jsonElement, final Appendable writer) throws JsonIOException {
|
||||
getHandle().toJson(((JsonElementHandle) jsonElement).getHandle(), writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(final cn.citycraft.GsonAgent.api.JsonElement jsonElement, final cn.citycraft.GsonAgent.api.stream.JsonWriter writer) throws JsonIOException {
|
||||
getHandle().toJson(((JsonElementHandle) jsonElement).getHandle(), ((JsonWriterHandle) writer).getHandle());
|
||||
}
|
||||
@Override
|
||||
public void toJson(final cn.citycraft.GsonAgent.api.JsonElement jsonElement, final cn.citycraft.GsonAgent.api.stream.JsonWriter writer) throws JsonIOException {
|
||||
getHandle().toJson(((JsonElementHandle) jsonElement).getHandle(), ((JsonWriterHandle) writer).getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJson(final Object src) {
|
||||
return getHandle().toJson(src);
|
||||
}
|
||||
@Override
|
||||
public String toJson(final Object src) {
|
||||
return getHandle().toJson(src);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(final Object src, final Appendable writer) throws JsonIOException {
|
||||
getHandle().toJson(src, writer);
|
||||
}
|
||||
@Override
|
||||
public void toJson(final Object src, final Appendable writer) throws JsonIOException {
|
||||
getHandle().toJson(src, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJson(final Object src, final Type typeOfSrc) {
|
||||
return getHandle().toJson(src, typeOfSrc);
|
||||
}
|
||||
@Override
|
||||
public String toJson(final Object src, final Type typeOfSrc) {
|
||||
return getHandle().toJson(src, typeOfSrc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(final Object src, final Type typeOfSrc, final Appendable writer) throws JsonIOException {
|
||||
getHandle().toJson(src, typeOfSrc, writer);
|
||||
}
|
||||
@Override
|
||||
public void toJson(final Object src, final Type typeOfSrc, final Appendable writer) throws JsonIOException {
|
||||
getHandle().toJson(src, typeOfSrc, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(final Object src, final Type typeOfSrc, final cn.citycraft.GsonAgent.api.stream.JsonWriter writer) throws JsonIOException {
|
||||
getHandle().toJson(src, typeOfSrc, ((JsonWriterHandle) writer).getHandle());
|
||||
}
|
||||
@Override
|
||||
public void toJson(final Object src, final Type typeOfSrc, final cn.citycraft.GsonAgent.api.stream.JsonWriter writer) throws JsonIOException {
|
||||
getHandle().toJson(src, typeOfSrc, ((JsonWriterHandle) writer).getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElementHandle toJsonTree(final Object src) {
|
||||
return new JsonElementHandle(getHandle().toJsonTree(src));
|
||||
}
|
||||
@Override
|
||||
public JsonElementHandle toJsonTree(final Object src) {
|
||||
return new JsonElementHandle(getHandle().toJsonTree(src));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElementHandle toJsonTree(final Object src, final Type typeOfSrc) {
|
||||
return new JsonElementHandle(getHandle().toJsonTree(src, typeOfSrc));
|
||||
}
|
||||
@Override
|
||||
public JsonElementHandle toJsonTree(final Object src, final Type typeOfSrc) {
|
||||
return new JsonElementHandle(getHandle().toJsonTree(src, typeOfSrc));
|
||||
}
|
||||
}
|
||||
|
@ -17,143 +17,143 @@ import cn.citycraft.GsonAgent.api.utils.Utils;
|
||||
*/
|
||||
public class JsonArrayHandle extends JsonElementHandle implements JsonArray {
|
||||
|
||||
private static Field elementsField;
|
||||
private static Field elementsField;
|
||||
|
||||
static {
|
||||
try {
|
||||
elementsField = com.google.gson.JsonArray.class.getDeclaredField("elements");
|
||||
elementsField.setAccessible(true);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
static {
|
||||
try {
|
||||
elementsField = com.google.gson.JsonArray.class.getDeclaredField("elements");
|
||||
elementsField.setAccessible(true);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private final com.google.gson.JsonArray handle;
|
||||
private final com.google.gson.JsonArray handle;
|
||||
|
||||
private List<com.google.gson.JsonElement> elements;
|
||||
private List<com.google.gson.JsonElement> elements;
|
||||
|
||||
public JsonArrayHandle() {
|
||||
this(new com.google.gson.JsonArray());
|
||||
}
|
||||
public JsonArrayHandle() {
|
||||
this(new com.google.gson.JsonArray());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected JsonArrayHandle(final com.google.gson.JsonArray handle) {
|
||||
this.handle = handle;
|
||||
try {
|
||||
elements = (List<com.google.gson.JsonElement>) elementsField.get(this.handle);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
protected JsonArrayHandle(final com.google.gson.JsonArray handle) {
|
||||
this.handle = handle;
|
||||
try {
|
||||
elements = (List<com.google.gson.JsonElement>) elementsField.get(this.handle);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(final cn.citycraft.GsonAgent.api.JsonElement element) {
|
||||
handle.add(((JsonElementHandle) element).getHandle());
|
||||
}
|
||||
@Override
|
||||
public void add(final cn.citycraft.GsonAgent.api.JsonElement element) {
|
||||
handle.add(((JsonElementHandle) element).getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAll(final cn.citycraft.GsonAgent.api.JsonArray array) {
|
||||
handle.addAll(((JsonArrayHandle) array).handle);
|
||||
}
|
||||
@Override
|
||||
public void addAll(final cn.citycraft.GsonAgent.api.JsonArray array) {
|
||||
handle.addAll(((JsonArrayHandle) array).handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonArray deepCopy() {
|
||||
return new JsonArrayHandle(Utils.deepCopyObject(this.handle));
|
||||
}
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonArray deepCopy() {
|
||||
return new JsonArrayHandle(Utils.deepCopyObject(this.handle));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
return handle.equals(o);
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
return handle.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonElement get(final int i) {
|
||||
return new JsonElementHandle(handle.get(i));
|
||||
}
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonElement get(final int i) {
|
||||
return new JsonElementHandle(handle.get(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getAsBigDecimal() {
|
||||
return handle.getAsBigDecimal();
|
||||
}
|
||||
@Override
|
||||
public BigDecimal getAsBigDecimal() {
|
||||
return handle.getAsBigDecimal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger getAsBigInteger() {
|
||||
return handle.getAsBigInteger();
|
||||
}
|
||||
@Override
|
||||
public BigInteger getAsBigInteger() {
|
||||
return handle.getAsBigInteger();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return handle.getAsBoolean();
|
||||
}
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return handle.getAsBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getAsByte() {
|
||||
return handle.getAsByte();
|
||||
}
|
||||
@Override
|
||||
public byte getAsByte() {
|
||||
return handle.getAsByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getAsCharacter() {
|
||||
return handle.getAsCharacter();
|
||||
}
|
||||
@Override
|
||||
public char getAsCharacter() {
|
||||
return handle.getAsCharacter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAsDouble() {
|
||||
return handle.getAsDouble();
|
||||
}
|
||||
@Override
|
||||
public double getAsDouble() {
|
||||
return handle.getAsDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAsFloat() {
|
||||
return handle.getAsFloat();
|
||||
}
|
||||
@Override
|
||||
public float getAsFloat() {
|
||||
return handle.getAsFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
return handle.getAsInt();
|
||||
}
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
return handle.getAsInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAsLong() {
|
||||
return handle.getAsLong();
|
||||
}
|
||||
@Override
|
||||
public long getAsLong() {
|
||||
return handle.getAsLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAsNumber() {
|
||||
return handle.getAsNumber();
|
||||
}
|
||||
@Override
|
||||
public Number getAsNumber() {
|
||||
return handle.getAsNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getAsShort() {
|
||||
return handle.getAsShort();
|
||||
}
|
||||
@Override
|
||||
public short getAsShort() {
|
||||
return handle.getAsShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString() {
|
||||
return handle.getAsString();
|
||||
}
|
||||
@Override
|
||||
public String getAsString() {
|
||||
return handle.getAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<cn.citycraft.GsonAgent.api.JsonElement> iterator() {
|
||||
try {
|
||||
final List<cn.citycraft.GsonAgent.api.JsonElement> result = new ArrayList<>();
|
||||
final Iterator<com.google.gson.JsonElement> iterator = this.elements.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
result.add(new JsonElementHandle(iterator.next()));
|
||||
}
|
||||
return result.iterator();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Iterator<cn.citycraft.GsonAgent.api.JsonElement> iterator() {
|
||||
try {
|
||||
final List<cn.citycraft.GsonAgent.api.JsonElement> result = new ArrayList<>();
|
||||
final Iterator<com.google.gson.JsonElement> iterator = this.elements.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
result.add(new JsonElementHandle(iterator.next()));
|
||||
}
|
||||
return result.iterator();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return handle.size();
|
||||
}
|
||||
@Override
|
||||
public int size() {
|
||||
return handle.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,127 +17,127 @@ import cn.citycraft.GsonAgent.api.utils.Utils;
|
||||
*/
|
||||
public class JsonElementHandle implements JsonElement {
|
||||
|
||||
private com.google.gson.JsonElement handle;
|
||||
private com.google.gson.JsonElement handle;
|
||||
|
||||
public JsonElementHandle() {
|
||||
}
|
||||
public JsonElementHandle() {
|
||||
}
|
||||
|
||||
public JsonElementHandle(final com.google.gson.JsonElement handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
public JsonElementHandle(final com.google.gson.JsonElement handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonElement deepCopy() {
|
||||
return new JsonElementHandle(Utils.deepCopyObject(this.getHandle()));
|
||||
}
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonElement deepCopy() {
|
||||
return new JsonElementHandle(Utils.deepCopyObject(this.getHandle()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getAsBigDecimal() {
|
||||
return getHandle().getAsBigDecimal();
|
||||
}
|
||||
@Override
|
||||
public BigDecimal getAsBigDecimal() {
|
||||
return getHandle().getAsBigDecimal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger getAsBigInteger() {
|
||||
return getHandle().getAsBigInteger();
|
||||
}
|
||||
@Override
|
||||
public BigInteger getAsBigInteger() {
|
||||
return getHandle().getAsBigInteger();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return getHandle().getAsBoolean();
|
||||
}
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return getHandle().getAsBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getAsByte() {
|
||||
return getHandle().getAsByte();
|
||||
}
|
||||
@Override
|
||||
public byte getAsByte() {
|
||||
return getHandle().getAsByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getAsCharacter() {
|
||||
return getHandle().getAsCharacter();
|
||||
}
|
||||
@Override
|
||||
public char getAsCharacter() {
|
||||
return getHandle().getAsCharacter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAsDouble() {
|
||||
return getHandle().getAsDouble();
|
||||
}
|
||||
@Override
|
||||
public double getAsDouble() {
|
||||
return getHandle().getAsDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAsFloat() {
|
||||
return getHandle().getAsFloat();
|
||||
}
|
||||
@Override
|
||||
public float getAsFloat() {
|
||||
return getHandle().getAsFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
return getHandle().getAsInt();
|
||||
}
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
return getHandle().getAsInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonArrayHandle getAsJsonArray() {
|
||||
return new JsonArrayHandle(getHandle().getAsJsonArray());
|
||||
}
|
||||
@Override
|
||||
public JsonArrayHandle getAsJsonArray() {
|
||||
return new JsonArrayHandle(getHandle().getAsJsonArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNullHandle getAsJsonNull() {
|
||||
return new JsonNullHandle(getHandle().getAsJsonNull());
|
||||
}
|
||||
@Override
|
||||
public JsonNullHandle getAsJsonNull() {
|
||||
return new JsonNullHandle(getHandle().getAsJsonNull());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObjectHandle getAsJsonObject() {
|
||||
return new JsonObjectHandle(getHandle().getAsJsonObject());
|
||||
}
|
||||
@Override
|
||||
public JsonObjectHandle getAsJsonObject() {
|
||||
return new JsonObjectHandle(getHandle().getAsJsonObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonPrimitiveHandle getAsJsonPrimitive() {
|
||||
return new JsonPrimitiveHandle(getHandle().getAsJsonPrimitive());
|
||||
}
|
||||
@Override
|
||||
public JsonPrimitiveHandle getAsJsonPrimitive() {
|
||||
return new JsonPrimitiveHandle(getHandle().getAsJsonPrimitive());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAsLong() {
|
||||
return getHandle().getAsLong();
|
||||
}
|
||||
@Override
|
||||
public long getAsLong() {
|
||||
return getHandle().getAsLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAsNumber() {
|
||||
return getHandle().getAsNumber();
|
||||
}
|
||||
@Override
|
||||
public Number getAsNumber() {
|
||||
return getHandle().getAsNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getAsShort() {
|
||||
return getHandle().getAsShort();
|
||||
}
|
||||
@Override
|
||||
public short getAsShort() {
|
||||
return getHandle().getAsShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString() {
|
||||
return getHandle().getAsString();
|
||||
}
|
||||
@Override
|
||||
public String getAsString() {
|
||||
return getHandle().getAsString();
|
||||
}
|
||||
|
||||
public com.google.gson.JsonElement getHandle() {
|
||||
return handle;
|
||||
}
|
||||
public com.google.gson.JsonElement getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJsonArray() {
|
||||
return getHandle().isJsonArray();
|
||||
}
|
||||
@Override
|
||||
public boolean isJsonArray() {
|
||||
return getHandle().isJsonArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJsonNull() {
|
||||
return getHandle().isJsonNull();
|
||||
}
|
||||
@Override
|
||||
public boolean isJsonNull() {
|
||||
return getHandle().isJsonNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJsonObject() {
|
||||
return getHandle().isJsonObject();
|
||||
}
|
||||
@Override
|
||||
public boolean isJsonObject() {
|
||||
return getHandle().isJsonObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJsonPrimitive() {
|
||||
return getHandle().isJsonPrimitive();
|
||||
}
|
||||
@Override
|
||||
public boolean isJsonPrimitive() {
|
||||
return getHandle().isJsonPrimitive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getHandle().toString();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return getHandle().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,28 +9,28 @@ import cn.citycraft.GsonAgent.api.JsonNull;
|
||||
*/
|
||||
public class JsonNullHandle extends JsonElementHandle implements JsonNull {
|
||||
|
||||
private final com.google.gson.JsonNull handle;
|
||||
private final com.google.gson.JsonNull handle;
|
||||
|
||||
public JsonNullHandle() {
|
||||
this(com.google.gson.JsonNull.INSTANCE);
|
||||
}
|
||||
public JsonNullHandle() {
|
||||
this(com.google.gson.JsonNull.INSTANCE);
|
||||
}
|
||||
|
||||
protected JsonNullHandle(final com.google.gson.JsonNull handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
protected JsonNullHandle(final com.google.gson.JsonNull handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonNull deepCopy() {
|
||||
return new JsonNullHandle();
|
||||
}
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonNull deepCopy() {
|
||||
return new JsonNullHandle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object other) {
|
||||
return handle.equals(other);
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final Object other) {
|
||||
return handle.equals(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
}
|
||||
|
@ -20,116 +20,116 @@ import cn.citycraft.GsonAgent.api.utils.Utils;
|
||||
*/
|
||||
public class JsonObjectHandle extends JsonElementHandle implements JsonObject {
|
||||
|
||||
private static Field membersField;
|
||||
private static Field membersField;
|
||||
|
||||
static {
|
||||
try {
|
||||
membersField = com.google.gson.JsonObject.class.getDeclaredField("members");
|
||||
membersField.setAccessible(true);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
static {
|
||||
try {
|
||||
membersField = com.google.gson.JsonObject.class.getDeclaredField("members");
|
||||
membersField.setAccessible(true);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private final com.google.gson.JsonObject handle;
|
||||
private final com.google.gson.JsonObject handle;
|
||||
|
||||
private AbstractMap<String, com.google.gson.JsonElement> members;
|
||||
private AbstractMap<String, com.google.gson.JsonElement> members;
|
||||
|
||||
public JsonObjectHandle() {
|
||||
this(new com.google.gson.JsonObject());
|
||||
}
|
||||
public JsonObjectHandle() {
|
||||
this(new com.google.gson.JsonObject());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected JsonObjectHandle(final com.google.gson.JsonObject handle) {
|
||||
this.handle = handle;
|
||||
try {
|
||||
members = (AbstractMap<String, com.google.gson.JsonElement>) membersField.get(this.handle);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
protected JsonObjectHandle(final com.google.gson.JsonObject handle) {
|
||||
this.handle = handle;
|
||||
try {
|
||||
members = (AbstractMap<String, com.google.gson.JsonElement>) membersField.get(this.handle);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(final String property, final cn.citycraft.GsonAgent.api.JsonElement value) {
|
||||
handle.add(property, ((JsonElementHandle) value).getHandle());
|
||||
}
|
||||
@Override
|
||||
public void add(final String property, final cn.citycraft.GsonAgent.api.JsonElement value) {
|
||||
handle.add(property, ((JsonElementHandle) value).getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProperty(final String property, final Boolean value) {
|
||||
handle.addProperty(property, value);
|
||||
}
|
||||
@Override
|
||||
public void addProperty(final String property, final Boolean value) {
|
||||
handle.addProperty(property, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProperty(final String property, final Character value) {
|
||||
handle.addProperty(property, value);
|
||||
}
|
||||
@Override
|
||||
public void addProperty(final String property, final Character value) {
|
||||
handle.addProperty(property, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProperty(final String property, final Number value) {
|
||||
handle.addProperty(property, value);
|
||||
}
|
||||
@Override
|
||||
public void addProperty(final String property, final Number value) {
|
||||
handle.addProperty(property, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProperty(final String property, final String value) {
|
||||
handle.addProperty(property, value);
|
||||
}
|
||||
@Override
|
||||
public void addProperty(final String property, final String value) {
|
||||
handle.addProperty(property, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonObject deepCopy() {
|
||||
return new JsonObjectHandle(Utils.deepCopyObject(this.handle));
|
||||
}
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonObject deepCopy() {
|
||||
return new JsonObjectHandle(Utils.deepCopyObject(this.handle));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Map.Entry<String, cn.citycraft.GsonAgent.api.JsonElement>> entrySet() {
|
||||
try {
|
||||
final Map<String, cn.citycraft.GsonAgent.api.JsonElement> result = new LinkedTreeMap<>();
|
||||
for (final Map.Entry<String, com.google.gson.JsonElement> entry : members.entrySet()) {
|
||||
result.put(entry.getKey(), new JsonElementHandle(entry.getValue()));
|
||||
}
|
||||
return result.entrySet();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Set<Map.Entry<String, cn.citycraft.GsonAgent.api.JsonElement>> entrySet() {
|
||||
try {
|
||||
final Map<String, cn.citycraft.GsonAgent.api.JsonElement> result = new LinkedTreeMap<>();
|
||||
for (final Map.Entry<String, com.google.gson.JsonElement> entry : members.entrySet()) {
|
||||
result.put(entry.getKey(), new JsonElementHandle(entry.getValue()));
|
||||
}
|
||||
return result.entrySet();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
return handle.equals(o);
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
return handle.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElementHandle get(final String memberName) {
|
||||
return new JsonElementHandle(handle.get(memberName));
|
||||
}
|
||||
@Override
|
||||
public JsonElementHandle get(final String memberName) {
|
||||
return new JsonElementHandle(handle.get(memberName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonArrayHandle getAsJsonArray(final String memberName) {
|
||||
return new JsonArrayHandle(handle.getAsJsonArray(memberName));
|
||||
}
|
||||
@Override
|
||||
public JsonArrayHandle getAsJsonArray(final String memberName) {
|
||||
return new JsonArrayHandle(handle.getAsJsonArray(memberName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObjectHandle getAsJsonObject(final String memberName) {
|
||||
return new JsonObjectHandle(handle.getAsJsonObject(memberName));
|
||||
}
|
||||
@Override
|
||||
public JsonObjectHandle getAsJsonObject(final String memberName) {
|
||||
return new JsonObjectHandle(handle.getAsJsonObject(memberName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonPrimitiveHandle getAsJsonPrimitive(final String memberName) {
|
||||
return new JsonPrimitiveHandle(handle.getAsJsonPrimitive(memberName));
|
||||
}
|
||||
@Override
|
||||
public JsonPrimitiveHandle getAsJsonPrimitive(final String memberName) {
|
||||
return new JsonPrimitiveHandle(handle.getAsJsonPrimitive(memberName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(final String memberName) {
|
||||
return handle.has(memberName);
|
||||
}
|
||||
@Override
|
||||
public boolean has(final String memberName) {
|
||||
return handle.has(memberName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElementHandle remove(final String property) {
|
||||
return new JsonElementHandle(handle.remove(property));
|
||||
}
|
||||
@Override
|
||||
public JsonElementHandle remove(final String property) {
|
||||
return new JsonElementHandle(handle.remove(property));
|
||||
}
|
||||
}
|
||||
|
@ -8,34 +8,34 @@ import cn.citycraft.GsonAgent.normal.stream.JsonReaderHandle;
|
||||
|
||||
public class JsonParserHandle implements cn.citycraft.GsonAgent.api.JsonParser {
|
||||
|
||||
public com.google.gson.JsonParser handle;
|
||||
public com.google.gson.JsonParser handle;
|
||||
|
||||
public JsonParserHandle() {
|
||||
handle = new com.google.gson.JsonParser();
|
||||
}
|
||||
public JsonParserHandle() {
|
||||
handle = new com.google.gson.JsonParser();
|
||||
}
|
||||
|
||||
protected JsonParserHandle(final com.google.gson.JsonParser handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
protected JsonParserHandle(final com.google.gson.JsonParser handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.google.gson.JsonParser getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
@Override
|
||||
public com.google.gson.JsonParser getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElementHandle parse(final cn.citycraft.GsonAgent.api.stream.JsonReader json) throws JsonIOException, JsonSyntaxException {
|
||||
return new JsonElementHandle(getHandle().parse(((JsonReaderHandle) json).getHandle()));
|
||||
}
|
||||
@Override
|
||||
public JsonElementHandle parse(final cn.citycraft.GsonAgent.api.stream.JsonReader json) throws JsonIOException, JsonSyntaxException {
|
||||
return new JsonElementHandle(getHandle().parse(((JsonReaderHandle) json).getHandle()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElementHandle parse(final Reader json) throws JsonIOException, JsonSyntaxException {
|
||||
return new JsonElementHandle(getHandle().parse(json));
|
||||
}
|
||||
@Override
|
||||
public JsonElementHandle parse(final Reader json) throws JsonIOException, JsonSyntaxException {
|
||||
return new JsonElementHandle(getHandle().parse(json));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElementHandle parse(final String json) throws JsonSyntaxException {
|
||||
return new JsonElementHandle(getHandle().parse(json));
|
||||
}
|
||||
@Override
|
||||
public JsonElementHandle parse(final String json) throws JsonSyntaxException {
|
||||
return new JsonElementHandle(getHandle().parse(json));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,139 +16,139 @@ import cn.citycraft.GsonAgent.api.utils.Utils;
|
||||
*/
|
||||
public class JsonPrimitiveHandle extends JsonElementHandle implements JsonPrimitive {
|
||||
|
||||
private final com.google.gson.JsonPrimitive handle;
|
||||
private final com.google.gson.JsonPrimitive handle;
|
||||
|
||||
public JsonPrimitiveHandle(final Boolean bool) {
|
||||
this(new com.google.gson.JsonPrimitive(bool));
|
||||
setValue(bool);
|
||||
}
|
||||
public JsonPrimitiveHandle(final Boolean bool) {
|
||||
this(new com.google.gson.JsonPrimitive(bool));
|
||||
setValue(bool);
|
||||
}
|
||||
|
||||
public JsonPrimitiveHandle(final Character c) {
|
||||
this(new com.google.gson.JsonPrimitive(c));
|
||||
setValue(c);
|
||||
}
|
||||
public JsonPrimitiveHandle(final Character c) {
|
||||
this(new com.google.gson.JsonPrimitive(c));
|
||||
setValue(c);
|
||||
}
|
||||
|
||||
public JsonPrimitiveHandle(final Number number) {
|
||||
this(new com.google.gson.JsonPrimitive(number));
|
||||
setValue(number);
|
||||
}
|
||||
public JsonPrimitiveHandle(final Number number) {
|
||||
this(new com.google.gson.JsonPrimitive(number));
|
||||
setValue(number);
|
||||
}
|
||||
|
||||
public JsonPrimitiveHandle(final String string) {
|
||||
this(new com.google.gson.JsonPrimitive(string));
|
||||
setValue(string);
|
||||
}
|
||||
public JsonPrimitiveHandle(final String string) {
|
||||
this(new com.google.gson.JsonPrimitive(string));
|
||||
setValue(string);
|
||||
}
|
||||
|
||||
protected JsonPrimitiveHandle(final com.google.gson.JsonPrimitive handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
protected JsonPrimitiveHandle(final com.google.gson.JsonPrimitive handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonPrimitive deepCopy() {
|
||||
return new JsonPrimitiveHandle(Utils.deepCopyObject(this.handle));
|
||||
}
|
||||
@Override
|
||||
public cn.citycraft.GsonAgent.api.JsonPrimitive deepCopy() {
|
||||
return new JsonPrimitiveHandle(Utils.deepCopyObject(this.handle));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return handle.equals(obj);
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return handle.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getAsBigDecimal() {
|
||||
return handle.getAsBigDecimal();
|
||||
}
|
||||
@Override
|
||||
public BigDecimal getAsBigDecimal() {
|
||||
return handle.getAsBigDecimal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger getAsBigInteger() {
|
||||
return handle.getAsBigInteger();
|
||||
}
|
||||
@Override
|
||||
public BigInteger getAsBigInteger() {
|
||||
return handle.getAsBigInteger();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return handle.getAsBoolean();
|
||||
}
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return handle.getAsBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getAsByte() {
|
||||
return handle.getAsByte();
|
||||
}
|
||||
@Override
|
||||
public byte getAsByte() {
|
||||
return handle.getAsByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getAsCharacter() {
|
||||
return handle.getAsCharacter();
|
||||
}
|
||||
@Override
|
||||
public char getAsCharacter() {
|
||||
return handle.getAsCharacter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAsDouble() {
|
||||
return handle.getAsDouble();
|
||||
}
|
||||
@Override
|
||||
public double getAsDouble() {
|
||||
return handle.getAsDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAsFloat() {
|
||||
return handle.getAsFloat();
|
||||
}
|
||||
@Override
|
||||
public float getAsFloat() {
|
||||
return handle.getAsFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
return handle.getAsInt();
|
||||
}
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
return handle.getAsInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonArrayHandle getAsJsonArray() {
|
||||
return new JsonArrayHandle(handle.getAsJsonArray());
|
||||
}
|
||||
@Override
|
||||
public JsonArrayHandle getAsJsonArray() {
|
||||
return new JsonArrayHandle(handle.getAsJsonArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObjectHandle getAsJsonObject() {
|
||||
return new JsonObjectHandle(handle.getAsJsonObject());
|
||||
}
|
||||
@Override
|
||||
public JsonObjectHandle getAsJsonObject() {
|
||||
return new JsonObjectHandle(handle.getAsJsonObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAsLong() {
|
||||
return handle.getAsLong();
|
||||
}
|
||||
@Override
|
||||
public long getAsLong() {
|
||||
return handle.getAsLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAsNumber() {
|
||||
return handle.getAsNumber();
|
||||
}
|
||||
@Override
|
||||
public Number getAsNumber() {
|
||||
return handle.getAsNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getAsShort() {
|
||||
return handle.getAsShort();
|
||||
}
|
||||
@Override
|
||||
public short getAsShort() {
|
||||
return handle.getAsShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString() {
|
||||
return handle.getAsString();
|
||||
}
|
||||
@Override
|
||||
public String getAsString() {
|
||||
return handle.getAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBoolean() {
|
||||
return handle.isBoolean();
|
||||
}
|
||||
@Override
|
||||
public boolean isBoolean() {
|
||||
return handle.isBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNumber() {
|
||||
return handle.isNumber();
|
||||
}
|
||||
@Override
|
||||
public boolean isNumber() {
|
||||
return handle.isNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isString() {
|
||||
return handle.isString();
|
||||
}
|
||||
@Override
|
||||
public boolean isString() {
|
||||
return handle.isString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setValue(final Object primitive) {
|
||||
try {
|
||||
handle.getClass().getDeclaredMethod("setValue", Object.class).invoke(handle, primitive);
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public final void setValue(final Object primitive) {
|
||||
try {
|
||||
handle.getClass().getDeclaredMethod("setValue", Object.class).invoke(handle, primitive);
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,24 +10,24 @@ import cn.citycraft.GsonAgent.normal.GsonHandle;
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public class TypeAdapterFactoryHandle implements cn.citycraft.GsonAgent.api.TypeAdapterFactory, com.google.gson.TypeAdapterFactory {
|
||||
|
||||
private final TypeAdapterFactory handle;
|
||||
private final TypeAdapterFactory handle;
|
||||
|
||||
protected TypeAdapterFactoryHandle(final TypeAdapterFactory handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
protected TypeAdapterFactoryHandle(final TypeAdapterFactory handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> TypeAdapterHandle<T> create(final cn.citycraft.GsonAgent.api.Gson paramGson, final cn.citycraft.GsonAgent.api.reflect.TypeToken<T> paramTypeToken) {
|
||||
return new TypeAdapterHandle(this.create(((GsonHandle) paramGson).getHandle(), (TypeToken<T>) paramTypeToken.getHandle()));
|
||||
}
|
||||
@Override
|
||||
public <T> TypeAdapterHandle<T> create(final cn.citycraft.GsonAgent.api.Gson paramGson, final cn.citycraft.GsonAgent.api.reflect.TypeToken<T> paramTypeToken) {
|
||||
return new TypeAdapterHandle(this.create(((GsonHandle) paramGson).getHandle(), (TypeToken<T>) paramTypeToken.getHandle()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> TypeAdapter<T> create(final Gson paramGson, final TypeToken<T> paramTypeToken) {
|
||||
return this.getHandle().create(paramGson, paramTypeToken);
|
||||
}
|
||||
@Override
|
||||
public <T> TypeAdapter<T> create(final Gson paramGson, final TypeToken<T> paramTypeToken) {
|
||||
return this.getHandle().create(paramGson, paramTypeToken);
|
||||
}
|
||||
|
||||
public TypeAdapterFactory getHandle() {
|
||||
return handle;
|
||||
}
|
||||
public TypeAdapterFactory getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,65 +10,65 @@ import cn.citycraft.GsonAgent.api.utils.Utils;
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public class TypeTokenHandle<T> implements cn.citycraft.GsonAgent.api.reflect.TypeTokenAbstract<T> {
|
||||
|
||||
private TypeToken<T> handle;
|
||||
private TypeToken<T> handle;
|
||||
|
||||
public TypeTokenHandle() {
|
||||
try {
|
||||
handle = new TypeToken<T>() {
|
||||
};
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public TypeTokenHandle() {
|
||||
try {
|
||||
handle = new TypeToken<T>() {
|
||||
};
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public TypeTokenHandle(final Type type) {
|
||||
try {
|
||||
handle = Utils.newInstance(TypeToken.class, Type.class, type);
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public TypeTokenHandle(final Type type) {
|
||||
try {
|
||||
handle = Utils.newInstance(TypeToken.class, Type.class, type);
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected TypeTokenHandle(final TypeToken<T> handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
protected TypeTokenHandle(final TypeToken<T> handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
public static <T> TypeTokenAbstract<T> get(final Class<T> type) {
|
||||
return new TypeTokenHandle(TypeToken.get(type));
|
||||
}
|
||||
public static <T> TypeTokenAbstract<T> get(final Class<T> type) {
|
||||
return new TypeTokenHandle(TypeToken.get(type));
|
||||
}
|
||||
|
||||
public static TypeTokenAbstract<?> get(final Type type) {
|
||||
return new TypeTokenHandle(TypeToken.get(type));
|
||||
}
|
||||
public static TypeTokenAbstract<?> get(final Type type) {
|
||||
return new TypeTokenHandle(TypeToken.get(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeToken<T> getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
@Override
|
||||
public TypeToken<T> getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? super T> getRawType() {
|
||||
return getHandle().getRawType();
|
||||
}
|
||||
@Override
|
||||
public Class<? super T> getRawType() {
|
||||
return getHandle().getRawType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return getHandle().getType();
|
||||
}
|
||||
@Override
|
||||
public Type getType() {
|
||||
return getHandle().getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssignableFrom(final Class<?> cls) {
|
||||
return getHandle().isAssignableFrom(cls);
|
||||
}
|
||||
@Override
|
||||
public boolean isAssignableFrom(final Class<?> cls) {
|
||||
return getHandle().isAssignableFrom(cls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssignableFrom(final cn.citycraft.GsonAgent.api.reflect.TypeToken<?> token) {
|
||||
return getHandle().isAssignableFrom((TypeToken<?>) token.getHandle());
|
||||
}
|
||||
@Override
|
||||
public boolean isAssignableFrom(final cn.citycraft.GsonAgent.api.reflect.TypeToken<?> token) {
|
||||
return getHandle().isAssignableFrom((TypeToken<?>) token.getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssignableFrom(final Type from) {
|
||||
return getHandle().isAssignableFrom(from);
|
||||
}
|
||||
@Override
|
||||
public boolean isAssignableFrom(final Type from) {
|
||||
return getHandle().isAssignableFrom(from);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,108 +9,108 @@ import cn.citycraft.GsonAgent.api.stream.JsonToken;
|
||||
|
||||
public class JsonReaderHandle implements cn.citycraft.GsonAgent.api.stream.JsonReader {
|
||||
|
||||
private final JsonReader handle;
|
||||
private final JsonReader handle;
|
||||
|
||||
public JsonReaderHandle(final Reader in) {
|
||||
this(new JsonReader(in));
|
||||
}
|
||||
public JsonReaderHandle(final Reader in) {
|
||||
this(new JsonReader(in));
|
||||
}
|
||||
|
||||
protected JsonReaderHandle(final JsonReader handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
protected JsonReaderHandle(final JsonReader handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginArray() throws IOException {
|
||||
getHandle().beginArray();
|
||||
}
|
||||
@Override
|
||||
public void beginArray() throws IOException {
|
||||
getHandle().beginArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginObject() throws IOException {
|
||||
getHandle().beginObject();
|
||||
}
|
||||
@Override
|
||||
public void beginObject() throws IOException {
|
||||
getHandle().beginObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
getHandle().close();
|
||||
}
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
getHandle().close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endArray() throws IOException {
|
||||
getHandle().endArray();
|
||||
}
|
||||
@Override
|
||||
public void endArray() throws IOException {
|
||||
getHandle().endArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endObject() throws IOException {
|
||||
getHandle().endObject();
|
||||
}
|
||||
@Override
|
||||
public void endObject() throws IOException {
|
||||
getHandle().endObject();
|
||||
}
|
||||
|
||||
public JsonReader getHandle() {
|
||||
return handle;
|
||||
}
|
||||
public JsonReader getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() throws IOException {
|
||||
return getHandle().hasNext();
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() throws IOException {
|
||||
return getHandle().hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLenient() {
|
||||
return getHandle().isLenient();
|
||||
}
|
||||
@Override
|
||||
public boolean isLenient() {
|
||||
return getHandle().isLenient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextBoolean() throws IOException {
|
||||
return getHandle().nextBoolean();
|
||||
}
|
||||
@Override
|
||||
public boolean nextBoolean() throws IOException {
|
||||
return getHandle().nextBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextDouble() throws IOException {
|
||||
return getHandle().nextDouble();
|
||||
}
|
||||
@Override
|
||||
public double nextDouble() throws IOException {
|
||||
return getHandle().nextDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextInt() throws IOException {
|
||||
return getHandle().nextInt();
|
||||
}
|
||||
@Override
|
||||
public int nextInt() throws IOException {
|
||||
return getHandle().nextInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long nextLong() throws IOException {
|
||||
return getHandle().nextLong();
|
||||
}
|
||||
@Override
|
||||
public long nextLong() throws IOException {
|
||||
return getHandle().nextLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nextName() throws IOException {
|
||||
return getHandle().nextName();
|
||||
}
|
||||
@Override
|
||||
public String nextName() throws IOException {
|
||||
return getHandle().nextName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nextNull() throws IOException {
|
||||
getHandle().nextNull();
|
||||
}
|
||||
@Override
|
||||
public void nextNull() throws IOException {
|
||||
getHandle().nextNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nextString() throws IOException {
|
||||
return getHandle().nextString();
|
||||
}
|
||||
@Override
|
||||
public String nextString() throws IOException {
|
||||
return getHandle().nextString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonToken peek() throws IOException {
|
||||
return JsonToken.getByName(getHandle().peek().name());
|
||||
}
|
||||
@Override
|
||||
public JsonToken peek() throws IOException {
|
||||
return JsonToken.getByName(getHandle().peek().name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLenient(final boolean lenient) {
|
||||
getHandle().setLenient(lenient);
|
||||
}
|
||||
@Override
|
||||
public void setLenient(final boolean lenient) {
|
||||
getHandle().setLenient(lenient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void skipValue() throws IOException {
|
||||
getHandle().skipValue();
|
||||
}
|
||||
@Override
|
||||
public void skipValue() throws IOException {
|
||||
getHandle().skipValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getHandle().toString();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return getHandle().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,203 +6,481 @@ import java.lang.reflect.Field;
|
||||
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
public class JsonWriterHandle implements cn.citycraft.GsonAgent.api.stream.JsonWriter {
|
||||
import cn.citycraft.GsonAgent.api.utils.Utils;
|
||||
|
||||
private static String[] REPLACEMENT_CHARS;
|
||||
public class JsonWriterHandle extends JsonWriter implements cn.citycraft.GsonAgent.api.stream.JsonWriter {
|
||||
/*
|
||||
* From RFC 4627, "All Unicode characters may be placed within the
|
||||
* quotation marks except for the characters that must be escaped:
|
||||
* quotation mark, reverse solidus, and the control characters
|
||||
* (U+0000 through U+001F)."
|
||||
*
|
||||
* We also escape '\u2028' and '\u2029', which JavaScript interprets as
|
||||
* newline characters. This prevents eval() from failing with a syntax
|
||||
* error. http://code.google.com/p/google-gson/issues/detail?id=341
|
||||
*/
|
||||
private static Field stackField, stackSizeField, indentField, separatorField;
|
||||
|
||||
private static String[] HTML_SAFE_REPLACEMENT_CHARS;
|
||||
static {
|
||||
final Class<JsonWriter> clzz = JsonWriter.class;
|
||||
try {
|
||||
stackField = Utils.getDeclareField(clzz, "stack");
|
||||
stackSizeField = Utils.getDeclareField(clzz, "stackSize");
|
||||
indentField = Utils.getDeclareField(clzz, "indent");
|
||||
separatorField = Utils.getDeclareField(clzz, "separator");
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
Field field = JsonWriter.class.getDeclaredField("REPLACEMENT_CHARS");
|
||||
field.setAccessible(true);
|
||||
REPLACEMENT_CHARS = (String[]) field.get(null);
|
||||
field = JsonWriter.class.getDeclaredField("HTML_SAFE_REPLACEMENT_CHARS");
|
||||
field.setAccessible(true);
|
||||
HTML_SAFE_REPLACEMENT_CHARS = (String[]) field.get(null);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The output data, containing at most one top-level array or object.
|
||||
*/
|
||||
private final Writer out;
|
||||
private String deferredName;
|
||||
|
||||
private final JsonWriter handle;
|
||||
private boolean withoutQuotes = false;
|
||||
|
||||
private Writer out;
|
||||
/**
|
||||
* Creates a new instance that writes a JSON-encoded stream to {@code out}.
|
||||
* For best performance, ensure {@link Writer} is buffered; wrapping in
|
||||
* {@link java.io.BufferedWriter BufferedWriter} if necessary.
|
||||
*
|
||||
* @param out
|
||||
*/
|
||||
public JsonWriterHandle(final Writer out) {
|
||||
super(out);
|
||||
this.out = out;
|
||||
}
|
||||
|
||||
private boolean withoutQuotes = false;
|
||||
/**
|
||||
* Begins encoding a new array. Each call to this method must be paired with
|
||||
* a call to {@link #endArray}.
|
||||
*
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle beginArray() throws IOException {
|
||||
writeDeferredName();
|
||||
return open(EMPTY_ARRAY, "[");
|
||||
}
|
||||
|
||||
public JsonWriterHandle(final Writer out) {
|
||||
this(new JsonWriter(out));
|
||||
this.out = out;
|
||||
}
|
||||
/**
|
||||
* Begins encoding a new object. Each call to this method must be paired
|
||||
* with a call to {@link #endObject}.
|
||||
*
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle beginObject() throws IOException {
|
||||
writeDeferredName();
|
||||
return open(EMPTY_OBJECT, "{");
|
||||
}
|
||||
|
||||
protected JsonWriterHandle(final JsonWriter handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
/**
|
||||
* Flushes and closes this writer and the underlying {@link Writer}.
|
||||
*
|
||||
* @throws IOException
|
||||
* if the JSON document is incomplete.
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
out.close();
|
||||
final int size = this.getStackSize();
|
||||
if (size > 1 || size == 1 && this.getStack()[size - 1] != NONEMPTY_DOCUMENT) {
|
||||
throw new IOException("Incomplete document");
|
||||
}
|
||||
this.setStackSize(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle beginArray() throws IOException {
|
||||
getHandle().beginArray();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Ends encoding the current array.
|
||||
*
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle endArray() throws IOException {
|
||||
return close(EMPTY_ARRAY, NONEMPTY_ARRAY, "]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle beginObject() throws IOException {
|
||||
getHandle().beginObject();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Ends encoding the current object.
|
||||
*
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle endObject() throws IOException {
|
||||
return close(EMPTY_OBJECT, NONEMPTY_OBJECT, "}");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
getHandle().close();
|
||||
}
|
||||
/**
|
||||
* Ensures all buffered data is written to the underlying {@link Writer} and
|
||||
* flushes that writer.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
if (this.getStackSize() == 0) {
|
||||
throw new IllegalStateException("JsonWriterHandle is closed.");
|
||||
}
|
||||
out.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle endArray() throws IOException {
|
||||
getHandle().endArray();
|
||||
return this;
|
||||
}
|
||||
public JsonWriterHandle getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle endObject() throws IOException {
|
||||
getHandle().endObject();
|
||||
return this;
|
||||
}
|
||||
public String getIndent() {
|
||||
return Utils.invokeStringField(this, indentField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
getHandle().flush();
|
||||
}
|
||||
public String getSeparator() {
|
||||
return Utils.invokeStringField(this, separatorField);
|
||||
}
|
||||
|
||||
public JsonWriter getHandle() {
|
||||
return handle;
|
||||
}
|
||||
public int[] getStack() {
|
||||
return Utils.invokeIntArrayField(this, stackField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSerializeNulls() {
|
||||
return getHandle().getSerializeNulls();
|
||||
}
|
||||
public int getStackSize() {
|
||||
return Utils.invokeIntField(this, stackSizeField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHtmlSafe() {
|
||||
return getHandle().isHtmlSafe();
|
||||
}
|
||||
/**
|
||||
* Encodes the property name.
|
||||
*
|
||||
* @param name
|
||||
* the name of the forthcoming value. May not be null.
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle name(final String name) throws IOException {
|
||||
if (name == null) {
|
||||
throw new NullPointerException("name == null");
|
||||
}
|
||||
if (deferredName != null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
if (this.getStackSize() == 0) {
|
||||
throw new IllegalStateException("JsonWriterHandle is closed.");
|
||||
}
|
||||
deferredName = name;
|
||||
withoutQuotes = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLenient() {
|
||||
return getHandle().isLenient();
|
||||
}
|
||||
@Override
|
||||
public JsonWriterHandle nameWithoutQuotes(final String name) throws IOException {
|
||||
this.name(name);
|
||||
withoutQuotes = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle name(final String name) throws IOException {
|
||||
getHandle().name(name);
|
||||
withoutQuotes = false;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Encodes {@code null}.
|
||||
*
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle nullValue() throws IOException {
|
||||
if (deferredName != null) {
|
||||
if (this.getSerializeNulls()) {
|
||||
writeDeferredName();
|
||||
} else {
|
||||
deferredName = null;
|
||||
return this; // skip the name and the value
|
||||
}
|
||||
}
|
||||
beforeValue(false);
|
||||
out.write("null");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle nameWithoutQuotes(final String name) throws IOException {
|
||||
getHandle().name(name);
|
||||
withoutQuotes = true;
|
||||
return this;
|
||||
}
|
||||
public void setSeparator(final String separator) {
|
||||
Utils.modifyField(this, separatorField, separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle nullValue() throws IOException {
|
||||
getHandle().nullValue();
|
||||
return this;
|
||||
}
|
||||
public void setStack(final int index, final int value) {
|
||||
final int[] newStack = this.getStack();
|
||||
newStack[index] = value;
|
||||
this.setStack(newStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHtmlSafe(final boolean htmlSafe) {
|
||||
getHandle().setHtmlSafe(htmlSafe);
|
||||
}
|
||||
public void setStack(final int[] stack) {
|
||||
Utils.modifyField(this, stackField, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIndent(final String indent) {
|
||||
getHandle().setIndent(indent);
|
||||
}
|
||||
public void setStackSize(final int stackSize) {
|
||||
Utils.modifyField(this, stackSizeField, stackSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLenient(final boolean lenient) {
|
||||
getHandle().setLenient(lenient);
|
||||
}
|
||||
public void stringExtend(final String value) throws IOException {
|
||||
final String[] replacements = this.isHtmlSafe() ? Utils.HTML_SAFE_REPLACEMENT_CHARS : Utils.REPLACEMENT_CHARS;
|
||||
if (!this.withoutQuotes) {
|
||||
this.out.write("\"");
|
||||
}
|
||||
int last = 0;
|
||||
final int length = value.length();
|
||||
for (int i = 0; i < length; i++) {
|
||||
final char c = value.charAt(i);
|
||||
String replacement;
|
||||
if (c < 128) {
|
||||
replacement = replacements[c];
|
||||
if (replacement == null) {
|
||||
continue;
|
||||
}
|
||||
} else if (c == '\u2028') {
|
||||
replacement = "\\u2028";
|
||||
} else if (c == '\u2029') {
|
||||
replacement = "\\u2029";
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
if (last < i) {
|
||||
out.write(value, last, i - last);
|
||||
}
|
||||
out.write(replacement);
|
||||
last = i + 1;
|
||||
}
|
||||
if (last < length) {
|
||||
out.write(value, last, length - last);
|
||||
}
|
||||
if (!this.withoutQuotes) {
|
||||
this.out.write("\"");
|
||||
}
|
||||
withoutQuotes = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSerializeNulls(final boolean serializeNulls) {
|
||||
getHandle().setSerializeNulls(serializeNulls);
|
||||
}
|
||||
/**
|
||||
* Encodes {@code value}.
|
||||
*
|
||||
* @param value
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle value(final boolean value) throws IOException {
|
||||
writeDeferredName();
|
||||
beforeValue(false);
|
||||
out.write(value ? "true" : "false");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void string(final String value) throws IOException {
|
||||
final String[] replacements = getHandle().isHtmlSafe() ? HTML_SAFE_REPLACEMENT_CHARS : REPLACEMENT_CHARS;
|
||||
if (!this.withoutQuotes) {
|
||||
this.out.write("\"");
|
||||
}
|
||||
int last = 0;
|
||||
final int length = value.length();
|
||||
for (int i = 0; i < length; i++) {
|
||||
final char c = value.charAt(i);
|
||||
String replacement;
|
||||
if (c < '') {
|
||||
replacement = replacements[c];
|
||||
if (replacement == null) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (c == '
') {
|
||||
replacement = "\\u2028";
|
||||
} else {
|
||||
if (c != '
') {
|
||||
continue;
|
||||
}
|
||||
replacement = "\\u2029";
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Encodes {@code value}.
|
||||
*
|
||||
* @param value
|
||||
* a finite value. May not be {@link Double#isNaN() NaNs} or
|
||||
* {@link Double#isInfinite() infinities}.
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle value(final double value) throws IOException {
|
||||
if (Double.isNaN(value) || Double.isInfinite(value)) {
|
||||
throw new IllegalArgumentException("Numeric values must be finite, but was " + value);
|
||||
}
|
||||
writeDeferredName();
|
||||
beforeValue(false);
|
||||
out.append(Double.toString(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
if (last < i) {
|
||||
this.out.write(value, last, i - last);
|
||||
}
|
||||
this.out.write(replacement);
|
||||
last = i + 1;
|
||||
}
|
||||
if (last < length) {
|
||||
this.out.write(value, last, length - last);
|
||||
}
|
||||
if (!this.withoutQuotes) {
|
||||
this.out.write("\"");
|
||||
}
|
||||
withoutQuotes = false;
|
||||
}
|
||||
/**
|
||||
* Encodes {@code value}.
|
||||
*
|
||||
* @param value
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle value(final long value) throws IOException {
|
||||
writeDeferredName();
|
||||
beforeValue(false);
|
||||
out.write(Long.toString(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle value(final boolean value) throws IOException {
|
||||
getHandle().value(value);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Encodes {@code value}.
|
||||
*
|
||||
* @param value
|
||||
* a finite value. May not be {@link Double#isNaN() NaNs} or
|
||||
* {@link Double#isInfinite() infinities}.
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle value(final Number value) throws IOException {
|
||||
if (value == null) {
|
||||
return nullValue();
|
||||
}
|
||||
writeDeferredName();
|
||||
final String string = value.toString();
|
||||
if (!this.isLenient() && (string.equals("-Infinity") || string.equals("Infinity") || string.equals("NaN"))) {
|
||||
throw new IllegalArgumentException("Numeric values must be finite, but was " + value);
|
||||
}
|
||||
beforeValue(false);
|
||||
out.append(string);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle value(final double value) throws IOException {
|
||||
getHandle().value(value);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Encodes {@code value}.
|
||||
*
|
||||
* @param value
|
||||
* the literal string value, or null to encode a null literal.
|
||||
* @return this writer.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JsonWriterHandle value(final String value) throws IOException {
|
||||
if (value == null) {
|
||||
return nullValue();
|
||||
}
|
||||
writeDeferredName();
|
||||
beforeValue(false);
|
||||
stringExtend(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle value(final long value) throws IOException {
|
||||
getHandle().value(value);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Inserts any necessary separators and whitespace before a name. Also
|
||||
* adjusts the stack to expect the name's value.
|
||||
*/
|
||||
private void beforeName() throws IOException {
|
||||
final int context = peek();
|
||||
if (context == NONEMPTY_OBJECT) { // first in object
|
||||
out.write(',');
|
||||
} else if (context != EMPTY_OBJECT) { // not in an object!
|
||||
throw new IllegalStateException("Nesting problem.");
|
||||
}
|
||||
newline();
|
||||
replaceTop(DANGLING_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle value(final Number value) throws IOException {
|
||||
getHandle().value(value);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Inserts any necessary separators and whitespace before a literal value,
|
||||
* inline array, or inline object. Also adjusts the stack to expect either a
|
||||
* closing bracket or another element.
|
||||
*
|
||||
* @param root
|
||||
* true if the value is a new array or object, the two values
|
||||
* permitted as top-level elements.
|
||||
*/
|
||||
@SuppressWarnings("fallthrough")
|
||||
private void beforeValue(final boolean root) throws IOException {
|
||||
switch (peek()) {
|
||||
case NONEMPTY_DOCUMENT:
|
||||
if (!this.isLenient()) {
|
||||
throw new IllegalStateException("JSON must have only one top-level value.");
|
||||
}
|
||||
// fall-through
|
||||
case EMPTY_DOCUMENT: // first in document
|
||||
if (!this.isLenient() && !root) {
|
||||
throw new IllegalStateException("JSON must start with an array or an object.");
|
||||
}
|
||||
replaceTop(NONEMPTY_DOCUMENT);
|
||||
break;
|
||||
case EMPTY_ARRAY: // first in array
|
||||
replaceTop(NONEMPTY_ARRAY);
|
||||
newline();
|
||||
break;
|
||||
case NONEMPTY_ARRAY: // another in array
|
||||
out.append(',');
|
||||
newline();
|
||||
break;
|
||||
case DANGLING_NAME: // value for name
|
||||
out.append(this.getSeparator());
|
||||
replaceTop(NONEMPTY_OBJECT);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Nesting problem.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonWriterHandle value(final String value) throws IOException {
|
||||
getHandle().value(value);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Closes the current scope by appending any necessary whitespace and the
|
||||
* given bracket.
|
||||
*/
|
||||
private JsonWriterHandle close(final int empty, final int nonempty, final String closeBracket) throws IOException {
|
||||
final int context = peek();
|
||||
if (context != nonempty && context != empty) {
|
||||
throw new IllegalStateException("Nesting problem.");
|
||||
}
|
||||
if (deferredName != null) {
|
||||
throw new IllegalStateException("Dangling name: " + deferredName);
|
||||
}
|
||||
this.setStackSize(this.getStackSize() - 1);
|
||||
if (context == nonempty) {
|
||||
newline();
|
||||
}
|
||||
out.write(closeBracket);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void newline() throws IOException {
|
||||
if (this.getIndent() == null) {
|
||||
return;
|
||||
}
|
||||
out.write("\n");
|
||||
for (int i = 1, size = this.getStackSize(); i < size; i++) {
|
||||
out.write(this.getIndent());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters a new scope by appending any necessary whitespace and the given
|
||||
* bracket.
|
||||
*/
|
||||
private JsonWriterHandle open(final int empty, final String openBracket) throws IOException {
|
||||
beforeValue(true);
|
||||
push(empty);
|
||||
out.write(openBracket);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value on the top of the stack.
|
||||
*/
|
||||
private int peek() {
|
||||
if (this.getStackSize() == 0) {
|
||||
throw new IllegalStateException("JsonWriterHandle is closed.");
|
||||
}
|
||||
return this.getStack()[this.getStackSize() - 1];
|
||||
}
|
||||
|
||||
private void push(final int newTop) {
|
||||
int[] stacks = this.getStack();
|
||||
if (this.getStackSize() == stacks.length) {
|
||||
final int[] newStack = new int[stacks.length * 2];
|
||||
System.arraycopy(stacks, 0, newStack, 0, stacks.length);
|
||||
stacks = newStack;
|
||||
this.setStack(stacks);
|
||||
}
|
||||
this.setStack(this.getStackSize(), newTop);
|
||||
this.setStackSize(this.getStackSize() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the value on the top of the stack with the given value.
|
||||
*/
|
||||
private void replaceTop(final int topOfStack) {
|
||||
this.getStack()[this.getStackSize() - 1] = topOfStack;
|
||||
}
|
||||
|
||||
private void writeDeferredName() throws IOException {
|
||||
if (deferredName != null) {
|
||||
beforeName();
|
||||
stringExtend(deferredName);
|
||||
deferredName = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user