JsonElement
This commit is contained in:
@@ -17,7 +17,7 @@ import org.redkale.util.*;
|
|||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
* @since 2.8.0
|
* @since 2.8.0
|
||||||
*/
|
*/
|
||||||
public class JsonArray extends ArrayList<Object> implements JsonEntity {
|
public class JsonArray extends ArrayList<Object> implements JsonElement {
|
||||||
|
|
||||||
public JsonArray() {
|
public JsonArray() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import org.redkale.util.Utility;
|
|||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
* @since 2.8.0
|
* @since 2.8.0
|
||||||
*/
|
*/
|
||||||
public interface JsonEntity extends java.io.Serializable {
|
public interface JsonElement extends java.io.Serializable {
|
||||||
|
|
||||||
public boolean isObject();
|
public boolean isObject();
|
||||||
|
|
||||||
@@ -22,20 +22,20 @@ public interface JsonEntity extends java.io.Serializable {
|
|||||||
|
|
||||||
public boolean isString();
|
public boolean isString();
|
||||||
|
|
||||||
public static JsonEntity convertFrom(String text) {
|
public static JsonElement convertFrom(String text) {
|
||||||
return convertFrom(Utility.charArray(text));
|
return convertFrom(Utility.charArray(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonEntity convertFrom(char[] text) {
|
public static JsonElement convertFrom(char[] text) {
|
||||||
return convertFrom(text, 0, text.length);
|
return convertFrom(text, 0, text.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonEntity convertFrom(char[] text, final int offset, final int length) {
|
public static JsonElement convertFrom(char[] text, final int offset, final int length) {
|
||||||
Object val = JsonConvert.root().convertFrom(JsonEntity.class, text, offset, length);
|
Object val = JsonConvert.root().convertFrom(JsonElement.class, text, offset, length);
|
||||||
if (val instanceof CharSequence) {
|
if (val instanceof CharSequence) {
|
||||||
return new JsonString(val.toString());
|
return new JsonString(val.toString());
|
||||||
}
|
}
|
||||||
return (JsonEntity) val;
|
return (JsonElement) val;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -18,26 +18,26 @@ import org.redkale.util.*;
|
|||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
* @since 2.8.0
|
* @since 2.8.0
|
||||||
*/
|
*/
|
||||||
class JsonEntityDecoder extends AnyDecoder<JsonEntity> {
|
class JsonElementDecoder extends AnyDecoder<JsonElement> {
|
||||||
|
|
||||||
private static final Type arrayType = new TypeToken<Collection<JsonEntity>>() {
|
private static final Type arrayType = new TypeToken<Collection<JsonElement>>() {
|
||||||
}.getType();
|
}.getType();
|
||||||
|
|
||||||
private static final Type objectType = new TypeToken<Map<String, JsonEntity>>() {
|
private static final Type objectType = new TypeToken<Map<String, JsonElement>>() {
|
||||||
}.getType();
|
}.getType();
|
||||||
|
|
||||||
private static final Creator<JsonArray> arrayCreator = Creator.create(JsonArray.class);
|
private static final Creator<JsonArray> arrayCreator = t -> new JsonArray();
|
||||||
|
|
||||||
private static final Creator<JsonObject> objectCreator = Creator.create(JsonObject.class);
|
private static final Creator<JsonObject> objectCreator = t -> new JsonObject();
|
||||||
|
|
||||||
public static final JsonEntityDecoder instance = new JsonEntityDecoder();
|
public static final JsonElementDecoder instance = new JsonElementDecoder();
|
||||||
|
|
||||||
public JsonEntityDecoder() {
|
public JsonElementDecoder() {
|
||||||
super(objectCreator, objectType, arrayCreator, arrayType, StringSimpledCoder.instance);
|
super(objectCreator, objectType, arrayCreator, arrayType, StringSimpledCoder.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type getType() {
|
public Type getType() {
|
||||||
return JsonEntity.class;
|
return JsonElement.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,10 +49,10 @@ public final class JsonFactory extends ConvertFactory<JsonReader, JsonWriter> {
|
|||||||
this.register(java.time.LocalTime.class, LocalTimeSimpledCoder.LocalTimeJsonSimpledCoder.instance);
|
this.register(java.time.LocalTime.class, LocalTimeSimpledCoder.LocalTimeJsonSimpledCoder.instance);
|
||||||
this.register(java.time.LocalDateTime.class, LocalDateTimeSimpledCoder.LocalDateTimeJsonSimpledCoder.instance);
|
this.register(java.time.LocalDateTime.class, LocalDateTimeSimpledCoder.LocalDateTimeJsonSimpledCoder.instance);
|
||||||
|
|
||||||
this.register(JsonEntity.class, (Decodeable) JsonEntityDecoder.instance);
|
this.register(JsonElement.class, (Decodeable) JsonElementDecoder.instance);
|
||||||
this.register(JsonString.class, (Decodeable) JsonEntityDecoder.instance);
|
this.register(JsonString.class, (Decodeable) JsonElementDecoder.instance);
|
||||||
this.register(JsonObject.class, (Decodeable) JsonEntityDecoder.instance);
|
this.register(JsonObject.class, (Decodeable) JsonElementDecoder.instance);
|
||||||
this.register(JsonArray.class, (Decodeable) JsonEntityDecoder.instance);
|
this.register(JsonArray.class, (Decodeable) JsonElementDecoder.instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import org.redkale.util.*;
|
|||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
* @since 2.8.0
|
* @since 2.8.0
|
||||||
*/
|
*/
|
||||||
public class JsonObject extends LinkedHashMap<String, Object> implements JsonEntity {
|
public class JsonObject extends LinkedHashMap<String, Object> implements JsonElement {
|
||||||
|
|
||||||
public JsonObject() {
|
public JsonObject() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import org.redkale.convert.ConvertDisabled;
|
|||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
* @since 2.8.0
|
* @since 2.8.0
|
||||||
*/
|
*/
|
||||||
public class JsonString implements CharSequence, JsonEntity, Comparable<JsonString> {
|
public class JsonString implements CharSequence, JsonElement, Comparable<JsonString> {
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user