JsonElement

This commit is contained in:
redkale
2023-09-14 23:20:24 +08:00
parent fc1487bda4
commit c1414de552
6 changed files with 21 additions and 21 deletions

View File

@@ -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() {
} }

View File

@@ -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;
} }
} }

View File

@@ -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;
} }
} }

View File

@@ -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);
} }
} }

View File

@@ -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() {
} }

View File

@@ -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;