Improve the speed of the JSON_ELEMENT TypeAdapter when the object graph has already been turned into a JsonElement
This commit is contained in:
parent
1023f0fe34
commit
62a9702385
@ -249,6 +249,15 @@ public final class JsonTreeReader extends JsonReader {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonElement nextJsonElement() throws IOException {
|
||||||
|
if (peek() == JsonToken.NAME) {
|
||||||
|
throw new IllegalStateException("Can't turn a name into a JsonElement");
|
||||||
|
}
|
||||||
|
final JsonElement element = (JsonElement) peekStack();
|
||||||
|
skipValue();
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
@Override public void close() throws IOException {
|
@Override public void close() throws IOException {
|
||||||
stack = new Object[] { SENTINEL_CLOSED };
|
stack = new Object[] { SENTINEL_CLOSED };
|
||||||
stackSize = 1;
|
stackSize = 1;
|
||||||
|
@ -677,6 +677,10 @@ public final class TypeAdapters {
|
|||||||
|
|
||||||
public static final TypeAdapter<JsonElement> JSON_ELEMENT = new TypeAdapter<JsonElement>() {
|
public static final TypeAdapter<JsonElement> JSON_ELEMENT = new TypeAdapter<JsonElement>() {
|
||||||
@Override public JsonElement read(JsonReader in) throws IOException {
|
@Override public JsonElement read(JsonReader in) throws IOException {
|
||||||
|
if (in instanceof JsonTreeReader) {
|
||||||
|
return ((JsonTreeReader) in).nextJsonElement();
|
||||||
|
}
|
||||||
|
|
||||||
switch (in.peek()) {
|
switch (in.peek()) {
|
||||||
case STRING:
|
case STRING:
|
||||||
return new JsonPrimitive(in.nextString());
|
return new JsonPrimitive(in.nextString());
|
||||||
|
Loading…
Reference in New Issue
Block a user