优化JsonObject
This commit is contained in:
@@ -38,7 +38,7 @@ public class JsonArray extends ArrayList<Object> implements JsonEntity {
|
|||||||
return convertFrom(text, 0, text.length);
|
return convertFrom(text, 0, text.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonArray convertFrom(char[] text, final int offset, final int length) {
|
public static JsonArray convertFrom(char[] text, int offset, int length) {
|
||||||
return (JsonArray) JsonEntityDecoder.instance.convertFrom(new JsonReader(text, offset, length));
|
return (JsonArray) JsonEntityDecoder.instance.convertFrom(new JsonReader(text, offset, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,12 +34,21 @@ public class JsonObject extends LinkedHashMap<String, Object> implements JsonEnt
|
|||||||
return convertFrom(text, 0, text.length);
|
return convertFrom(text, 0, text.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject convertFrom(char[] text, final int offset, final int length) {
|
public static JsonObject convertFrom(char[] text, int offset, int length) {
|
||||||
return (JsonObject) JsonEntityDecoder.instance.convertFrom(new JsonReader(text, offset, length));
|
return (JsonObject) JsonEntityDecoder.instance.convertFrom(new JsonReader(text, offset, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject of(Object javaBean) {
|
public static JsonObject of(Object bean) {
|
||||||
return convertFrom(JsonConvert.root().convertTo(javaBean));
|
if (bean instanceof CharSequence) {
|
||||||
|
return convertFrom(bean.toString());
|
||||||
|
}
|
||||||
|
if (bean instanceof JsonObject) {
|
||||||
|
return (JsonObject) bean;
|
||||||
|
}
|
||||||
|
if (bean instanceof Map) {
|
||||||
|
return new JsonObject((Map) bean);
|
||||||
|
}
|
||||||
|
return convertFrom(JsonConvert.root().convertTo(bean));
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonObject append(String key, Object value) {
|
public JsonObject append(String key, Object value) {
|
||||||
@@ -47,6 +56,11 @@ public class JsonObject extends LinkedHashMap<String, Object> implements JsonEnt
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JsonObject append(String key, Collection value) {
|
||||||
|
super.put(key, value == null || value instanceof JsonArray ? value : new JsonArray(value));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public JsonObject putObject(String key) {
|
public JsonObject putObject(String key) {
|
||||||
JsonObject val = new JsonObject();
|
JsonObject val = new JsonObject();
|
||||||
super.put(key, val);
|
super.put(key, val);
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class JsonString implements CharSequence, JsonEntity, Comparable<JsonStri
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(JsonString o) {
|
public int compareTo(JsonString o) {
|
||||||
return o == null ? -1 : CharSequence.compare(this, o.getValue());
|
return o == null || o.value == null ? (value == null ? 0 : 1) : (this.value == null ? -1 : this.value.compareTo(o.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user