mirror of
https://github.com/fankes/moshi.git
synced 2025-10-20 00:19:21 +08:00
Make token a nested type of the reader.
This is the only class which uses these tokens and it does not deserve a top-level type.
This commit is contained in:
@@ -46,7 +46,7 @@ public abstract class JsonAdapter<T> {
|
|||||||
final JsonAdapter<T> delegate = this;
|
final JsonAdapter<T> delegate = this;
|
||||||
return new JsonAdapter<T>() {
|
return new JsonAdapter<T>() {
|
||||||
@Override public T fromJson(JsonReader reader) throws IOException {
|
@Override public T fromJson(JsonReader reader) throws IOException {
|
||||||
if (reader.peek() == JsonToken.NULL) {
|
if (reader.peek() == JsonReader.Token.NULL) {
|
||||||
return reader.nextNull();
|
return reader.nextNull();
|
||||||
} else {
|
} else {
|
||||||
return delegate.fromJson(reader);
|
return delegate.fromJson(reader);
|
||||||
|
@@ -411,7 +411,7 @@ public class JsonReader implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* Returns the type of the next token without consuming it.
|
* Returns the type of the next token without consuming it.
|
||||||
*/
|
*/
|
||||||
public JsonToken peek() throws IOException {
|
public Token peek() throws IOException {
|
||||||
int p = peeked;
|
int p = peeked;
|
||||||
if (p == PEEKED_NONE) {
|
if (p == PEEKED_NONE) {
|
||||||
p = doPeek();
|
p = doPeek();
|
||||||
@@ -419,32 +419,32 @@ public class JsonReader implements Closeable {
|
|||||||
|
|
||||||
switch (p) {
|
switch (p) {
|
||||||
case PEEKED_BEGIN_OBJECT:
|
case PEEKED_BEGIN_OBJECT:
|
||||||
return JsonToken.BEGIN_OBJECT;
|
return Token.BEGIN_OBJECT;
|
||||||
case PEEKED_END_OBJECT:
|
case PEEKED_END_OBJECT:
|
||||||
return JsonToken.END_OBJECT;
|
return Token.END_OBJECT;
|
||||||
case PEEKED_BEGIN_ARRAY:
|
case PEEKED_BEGIN_ARRAY:
|
||||||
return JsonToken.BEGIN_ARRAY;
|
return Token.BEGIN_ARRAY;
|
||||||
case PEEKED_END_ARRAY:
|
case PEEKED_END_ARRAY:
|
||||||
return JsonToken.END_ARRAY;
|
return Token.END_ARRAY;
|
||||||
case PEEKED_SINGLE_QUOTED_NAME:
|
case PEEKED_SINGLE_QUOTED_NAME:
|
||||||
case PEEKED_DOUBLE_QUOTED_NAME:
|
case PEEKED_DOUBLE_QUOTED_NAME:
|
||||||
case PEEKED_UNQUOTED_NAME:
|
case PEEKED_UNQUOTED_NAME:
|
||||||
return JsonToken.NAME;
|
return Token.NAME;
|
||||||
case PEEKED_TRUE:
|
case PEEKED_TRUE:
|
||||||
case PEEKED_FALSE:
|
case PEEKED_FALSE:
|
||||||
return JsonToken.BOOLEAN;
|
return Token.BOOLEAN;
|
||||||
case PEEKED_NULL:
|
case PEEKED_NULL:
|
||||||
return JsonToken.NULL;
|
return Token.NULL;
|
||||||
case PEEKED_SINGLE_QUOTED:
|
case PEEKED_SINGLE_QUOTED:
|
||||||
case PEEKED_DOUBLE_QUOTED:
|
case PEEKED_DOUBLE_QUOTED:
|
||||||
case PEEKED_UNQUOTED:
|
case PEEKED_UNQUOTED:
|
||||||
case PEEKED_BUFFERED:
|
case PEEKED_BUFFERED:
|
||||||
return JsonToken.STRING;
|
return Token.STRING;
|
||||||
case PEEKED_LONG:
|
case PEEKED_LONG:
|
||||||
case PEEKED_NUMBER:
|
case PEEKED_NUMBER:
|
||||||
return JsonToken.NUMBER;
|
return Token.NUMBER;
|
||||||
case PEEKED_EOF:
|
case PEEKED_EOF:
|
||||||
return JsonToken.END_DOCUMENT;
|
return Token.END_DOCUMENT;
|
||||||
default:
|
default:
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
@@ -755,7 +755,7 @@ public class JsonReader implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next token, a {@link JsonToken#NAME property name}, and
|
* Returns the next token, a {@link Token#NAME property name}, and
|
||||||
* consumes it.
|
* consumes it.
|
||||||
*
|
*
|
||||||
* @throws java.io.IOException if the next token in the stream is not a property
|
* @throws java.io.IOException if the next token in the stream is not a property
|
||||||
@@ -783,7 +783,7 @@ public class JsonReader implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link JsonToken#STRING string} value of the next token,
|
* Returns the {@link Token#STRING string} value of the next token,
|
||||||
* consuming it. If the next token is a number, this method will return its
|
* consuming it. If the next token is a number, this method will return its
|
||||||
* string form.
|
* string form.
|
||||||
*
|
*
|
||||||
@@ -819,7 +819,7 @@ public class JsonReader implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link JsonToken#BOOLEAN boolean} value of the next token,
|
* Returns the {@link Token#BOOLEAN boolean} value of the next token,
|
||||||
* consuming it.
|
* consuming it.
|
||||||
*
|
*
|
||||||
* @throws IllegalStateException if the next token is not a boolean or if
|
* @throws IllegalStateException if the next token is not a boolean or if
|
||||||
@@ -866,7 +866,7 @@ public class JsonReader implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link JsonToken#NUMBER double} value of the next token,
|
* Returns the {@link Token#NUMBER double} value of the next token,
|
||||||
* consuming it. If the next token is a string, this method will attempt to
|
* consuming it. If the next token is a string, this method will attempt to
|
||||||
* parse it as a double using {@link Double#parseDouble(String)}.
|
* parse it as a double using {@link Double#parseDouble(String)}.
|
||||||
*
|
*
|
||||||
@@ -912,7 +912,7 @@ public class JsonReader implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link JsonToken#NUMBER long} value of the next token,
|
* Returns the {@link Token#NUMBER long} value of the next token,
|
||||||
* consuming it. If the next token is a string, this method will attempt to
|
* consuming it. If the next token is a string, this method will attempt to
|
||||||
* parse it as a long. If the next token's numeric value cannot be exactly
|
* parse it as a long. If the next token's numeric value cannot be exactly
|
||||||
* represented by a Java {@code long}, this method throws.
|
* represented by a Java {@code long}, this method throws.
|
||||||
@@ -1029,7 +1029,7 @@ public class JsonReader implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link JsonToken#NUMBER int} value of the next token,
|
* Returns the {@link Token#NUMBER int} value of the next token,
|
||||||
* consuming it. If the next token is a string, this method will attempt to
|
* consuming it. If the next token is a string, this method will attempt to
|
||||||
* parse it as an int. If the next token's numeric value cannot be exactly
|
* parse it as an int. If the next token's numeric value cannot be exactly
|
||||||
* represented by a Java {@code int}, this method throws.
|
* represented by a Java {@code int}, this method throws.
|
||||||
@@ -1375,4 +1375,69 @@ public class JsonReader implements Closeable {
|
|||||||
private IOException syntaxError(String message) throws IOException {
|
private IOException syntaxError(String message) throws IOException {
|
||||||
throw new IOException(message + " at path " + getPath());
|
throw new IOException(message + " at path " + getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A structure, name, or value type in a JSON-encoded string.
|
||||||
|
*/
|
||||||
|
public enum Token {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The opening of a JSON array. Written using {@link JsonWriter#beginArray}
|
||||||
|
* and read using {@link JsonReader#beginArray}.
|
||||||
|
*/
|
||||||
|
BEGIN_ARRAY,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The closing of a JSON array. Written using {@link JsonWriter#endArray}
|
||||||
|
* and read using {@link JsonReader#endArray}.
|
||||||
|
*/
|
||||||
|
END_ARRAY,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The opening of a JSON object. Written using {@link JsonWriter#beginObject}
|
||||||
|
* and read using {@link JsonReader#beginObject}.
|
||||||
|
*/
|
||||||
|
BEGIN_OBJECT,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The closing of a JSON object. Written using {@link JsonWriter#endObject}
|
||||||
|
* and read using {@link JsonReader#endObject}.
|
||||||
|
*/
|
||||||
|
END_OBJECT,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A JSON property name. Within objects, tokens alternate between names and
|
||||||
|
* their values. Written using {@link JsonWriter#name} and read using {@link
|
||||||
|
* JsonReader#nextName}
|
||||||
|
*/
|
||||||
|
NAME,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A JSON string.
|
||||||
|
*/
|
||||||
|
STRING,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A JSON number represented in this API by a Java {@code double}, {@code
|
||||||
|
* long}, or {@code int}.
|
||||||
|
*/
|
||||||
|
NUMBER,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A JSON {@code true} or {@code false}.
|
||||||
|
*/
|
||||||
|
BOOLEAN,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A JSON {@code null}.
|
||||||
|
*/
|
||||||
|
NULL,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The end of the JSON stream. This sentinel value is returned by {@link
|
||||||
|
* JsonReader#peek()} to signal that the JSON-encoded value has no more
|
||||||
|
* tokens.
|
||||||
|
*/
|
||||||
|
END_DOCUMENT
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2010 Google Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package com.squareup.moshi;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A structure, name or value type in a JSON-encoded string.
|
|
||||||
*/
|
|
||||||
public enum JsonToken {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The opening of a JSON array. Written using {@link JsonWriter#beginArray}
|
|
||||||
* and read using {@link JsonReader#beginArray}.
|
|
||||||
*/
|
|
||||||
BEGIN_ARRAY,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The closing of a JSON array. Written using {@link JsonWriter#endArray}
|
|
||||||
* and read using {@link JsonReader#endArray}.
|
|
||||||
*/
|
|
||||||
END_ARRAY,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The opening of a JSON object. Written using {@link JsonWriter#beginObject}
|
|
||||||
* and read using {@link JsonReader#beginObject}.
|
|
||||||
*/
|
|
||||||
BEGIN_OBJECT,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The closing of a JSON object. Written using {@link JsonWriter#endObject}
|
|
||||||
* and read using {@link JsonReader#endObject}.
|
|
||||||
*/
|
|
||||||
END_OBJECT,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A JSON property name. Within objects, tokens alternate between names and
|
|
||||||
* their values. Written using {@link JsonWriter#name} and read using {@link
|
|
||||||
* JsonReader#nextName}
|
|
||||||
*/
|
|
||||||
NAME,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A JSON string.
|
|
||||||
*/
|
|
||||||
STRING,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A JSON number represented in this API by a Java {@code double}, {@code
|
|
||||||
* long}, or {@code int}.
|
|
||||||
*/
|
|
||||||
NUMBER,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A JSON {@code true} or {@code false}.
|
|
||||||
*/
|
|
||||||
BOOLEAN,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A JSON {@code null}.
|
|
||||||
*/
|
|
||||||
NULL,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The end of the JSON stream. This sentinel value is returned by {@link
|
|
||||||
* JsonReader#peek()} to signal that the JSON-encoded value has no more
|
|
||||||
* tokens.
|
|
||||||
*/
|
|
||||||
END_DOCUMENT
|
|
||||||
}
|
|
@@ -24,15 +24,15 @@ import okio.Source;
|
|||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static com.squareup.moshi.JsonToken.BEGIN_ARRAY;
|
import static com.squareup.moshi.JsonReader.Token.BEGIN_ARRAY;
|
||||||
import static com.squareup.moshi.JsonToken.BEGIN_OBJECT;
|
import static com.squareup.moshi.JsonReader.Token.BEGIN_OBJECT;
|
||||||
import static com.squareup.moshi.JsonToken.BOOLEAN;
|
import static com.squareup.moshi.JsonReader.Token.BOOLEAN;
|
||||||
import static com.squareup.moshi.JsonToken.END_ARRAY;
|
import static com.squareup.moshi.JsonReader.Token.END_ARRAY;
|
||||||
import static com.squareup.moshi.JsonToken.END_OBJECT;
|
import static com.squareup.moshi.JsonReader.Token.END_OBJECT;
|
||||||
import static com.squareup.moshi.JsonToken.NAME;
|
import static com.squareup.moshi.JsonReader.Token.NAME;
|
||||||
import static com.squareup.moshi.JsonToken.NULL;
|
import static com.squareup.moshi.JsonReader.Token.NULL;
|
||||||
import static com.squareup.moshi.JsonToken.NUMBER;
|
import static com.squareup.moshi.JsonReader.Token.NUMBER;
|
||||||
import static com.squareup.moshi.JsonToken.STRING;
|
import static com.squareup.moshi.JsonReader.Token.STRING;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -46,7 +46,7 @@ public final class JsonReaderTest {
|
|||||||
assertEquals(true, reader.nextBoolean());
|
assertEquals(true, reader.nextBoolean());
|
||||||
assertEquals(true, reader.nextBoolean());
|
assertEquals(true, reader.nextBoolean());
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void readEmptyArray() throws IOException {
|
@Test public void readEmptyArray() throws IOException {
|
||||||
@@ -54,7 +54,7 @@ public final class JsonReaderTest {
|
|||||||
reader.beginArray();
|
reader.beginArray();
|
||||||
assertFalse(reader.hasNext());
|
assertFalse(reader.hasNext());
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void readObject() throws IOException {
|
@Test public void readObject() throws IOException {
|
||||||
@@ -65,7 +65,7 @@ public final class JsonReaderTest {
|
|||||||
assertEquals("b", reader.nextName());
|
assertEquals("b", reader.nextName());
|
||||||
assertEquals("banana", reader.nextString());
|
assertEquals("banana", reader.nextString());
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void readObjectBuffer() throws IOException {
|
@Test public void readObjectBuffer() throws IOException {
|
||||||
@@ -77,7 +77,7 @@ public final class JsonReaderTest {
|
|||||||
assertEquals("b", reader.nextName());
|
assertEquals("b", reader.nextName());
|
||||||
assertEquals("banana", reader.nextString());
|
assertEquals("banana", reader.nextString());
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void readObjectSource() throws IOException {
|
@Test public void readObjectSource() throws IOException {
|
||||||
@@ -90,7 +90,7 @@ public final class JsonReaderTest {
|
|||||||
assertEquals("b", reader.nextName());
|
assertEquals("b", reader.nextName());
|
||||||
assertEquals("banana", reader.nextString());
|
assertEquals("banana", reader.nextString());
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void readEmptyObject() throws IOException {
|
@Test public void readEmptyObject() throws IOException {
|
||||||
@@ -98,7 +98,7 @@ public final class JsonReaderTest {
|
|||||||
reader.beginObject();
|
reader.beginObject();
|
||||||
assertFalse(reader.hasNext());
|
assertFalse(reader.hasNext());
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void skipArray() throws IOException {
|
@Test public void skipArray() throws IOException {
|
||||||
@@ -109,7 +109,7 @@ public final class JsonReaderTest {
|
|||||||
assertEquals("b", reader.nextName());
|
assertEquals("b", reader.nextName());
|
||||||
assertEquals(123, reader.nextInt());
|
assertEquals(123, reader.nextInt());
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void skipArrayAfterPeek() throws Exception {
|
@Test public void skipArrayAfterPeek() throws Exception {
|
||||||
@@ -121,13 +121,13 @@ public final class JsonReaderTest {
|
|||||||
assertEquals("b", reader.nextName());
|
assertEquals("b", reader.nextName());
|
||||||
assertEquals(123, reader.nextInt());
|
assertEquals(123, reader.nextInt());
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void skipTopLevelObject() throws Exception {
|
@Test public void skipTopLevelObject() throws Exception {
|
||||||
JsonReader reader = new JsonReader("{\"a\": [\"one\", \"two\", \"three\"], \"b\": 123}");
|
JsonReader reader = new JsonReader("{\"a\": [\"one\", \"two\", \"three\"], \"b\": 123}");
|
||||||
reader.skipValue();
|
reader.skipValue();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void skipObject() throws IOException {
|
@Test public void skipObject() throws IOException {
|
||||||
@@ -139,7 +139,7 @@ public final class JsonReaderTest {
|
|||||||
assertEquals("b", reader.nextName());
|
assertEquals("b", reader.nextName());
|
||||||
reader.skipValue();
|
reader.skipValue();
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void skipObjectAfterPeek() throws Exception {
|
@Test public void skipObjectAfterPeek() throws Exception {
|
||||||
@@ -156,7 +156,7 @@ public final class JsonReaderTest {
|
|||||||
assertEquals("three", reader.nextName());
|
assertEquals("three", reader.nextName());
|
||||||
reader.skipValue();
|
reader.skipValue();
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void skipInteger() throws IOException {
|
@Test public void skipInteger() throws IOException {
|
||||||
@@ -167,7 +167,7 @@ public final class JsonReaderTest {
|
|||||||
assertEquals("b", reader.nextName());
|
assertEquals("b", reader.nextName());
|
||||||
reader.skipValue();
|
reader.skipValue();
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void skipDouble() throws IOException {
|
@Test public void skipDouble() throws IOException {
|
||||||
@@ -178,7 +178,7 @@ public final class JsonReaderTest {
|
|||||||
assertEquals("b", reader.nextName());
|
assertEquals("b", reader.nextName());
|
||||||
reader.skipValue();
|
reader.skipValue();
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void helloWorld() throws IOException {
|
@Test public void helloWorld() throws IOException {
|
||||||
@@ -195,7 +195,7 @@ public final class JsonReaderTest {
|
|||||||
assertEquals("world", reader.nextString());
|
assertEquals("world", reader.nextString());
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void nullString() {
|
@Test public void nullString() {
|
||||||
@@ -278,7 +278,7 @@ public final class JsonReaderTest {
|
|||||||
assertEquals("\u0019", reader.nextString());
|
assertEquals("\u0019", reader.nextString());
|
||||||
assertEquals("\u20AC", reader.nextString());
|
assertEquals("\u20AC", reader.nextString());
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void unescapingInvalidCharacters() throws IOException {
|
@Test public void unescapingInvalidCharacters() throws IOException {
|
||||||
@@ -344,7 +344,7 @@ public final class JsonReaderTest {
|
|||||||
assertEquals(3.141592653589793, reader.nextDouble(), 0d);
|
assertEquals(3.141592653589793, reader.nextDouble(), 0d);
|
||||||
assertEquals(2.718281828459045, reader.nextDouble(), 0d);
|
assertEquals(2.718281828459045, reader.nextDouble(), 0d);
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void strictNonFiniteDoubles() throws IOException {
|
@Test public void strictNonFiniteDoubles() throws IOException {
|
||||||
@@ -433,7 +433,7 @@ public final class JsonReaderTest {
|
|||||||
}
|
}
|
||||||
assertEquals(Long.MAX_VALUE, reader.nextLong());
|
assertEquals(Long.MAX_VALUE, reader.nextLong());
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test @Ignore public void numberWithOctalPrefix() throws IOException {
|
@Test @Ignore public void numberWithOctalPrefix() throws IOException {
|
||||||
@@ -462,7 +462,7 @@ public final class JsonReaderTest {
|
|||||||
}
|
}
|
||||||
assertEquals("01", reader.nextString());
|
assertEquals("01", reader.nextString());
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void booleans() throws IOException {
|
@Test public void booleans() throws IOException {
|
||||||
@@ -471,7 +471,7 @@ public final class JsonReaderTest {
|
|||||||
assertEquals(true, reader.nextBoolean());
|
assertEquals(true, reader.nextBoolean());
|
||||||
assertEquals(false, reader.nextBoolean());
|
assertEquals(false, reader.nextBoolean());
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void peekingUnquotedStringsPrefixedWithBooleans() throws IOException {
|
@Test public void peekingUnquotedStringsPrefixedWithBooleans() throws IOException {
|
||||||
@@ -529,7 +529,7 @@ public final class JsonReaderTest {
|
|||||||
JsonReader reader = new JsonReader("[" + s + "]");
|
JsonReader reader = new JsonReader("[" + s + "]");
|
||||||
reader.setLenient(true);
|
reader.setLenient(true);
|
||||||
reader.beginArray();
|
reader.beginArray();
|
||||||
assertEquals(JsonToken.STRING, reader.peek());
|
assertEquals(JsonReader.Token.STRING, reader.peek());
|
||||||
assertEquals(s, reader.nextString());
|
assertEquals(s, reader.nextString());
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
}
|
}
|
||||||
@@ -663,7 +663,7 @@ public final class JsonReaderTest {
|
|||||||
reader.nextNull();
|
reader.nextNull();
|
||||||
reader.nextNull();
|
reader.nextNull();
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void missingValue() throws IOException {
|
@Test public void missingValue() throws IOException {
|
||||||
@@ -775,7 +775,7 @@ public final class JsonReaderTest {
|
|||||||
} catch (IllegalStateException expected) {
|
} catch (IllegalStateException expected) {
|
||||||
}
|
}
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -929,7 +929,7 @@ public final class JsonReaderTest {
|
|||||||
reader = new JsonReader("a//");
|
reader = new JsonReader("a//");
|
||||||
reader.setLenient(true);
|
reader.setLenient(true);
|
||||||
assertEquals("a", reader.nextString());
|
assertEquals("a", reader.nextString());
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void strictCommentsWithSkipValue() throws IOException {
|
@Test public void strictCommentsWithSkipValue() throws IOException {
|
||||||
@@ -979,7 +979,7 @@ public final class JsonReaderTest {
|
|||||||
JsonReader reader = new JsonReader("abc");
|
JsonReader reader = new JsonReader("abc");
|
||||||
reader.setLenient(true);
|
reader.setLenient(true);
|
||||||
assertEquals("abc", reader.nextString());
|
assertEquals("abc", reader.nextString());
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void strictUnquotedNamesWithSkipValue() throws IOException {
|
@Test public void strictUnquotedNamesWithSkipValue() throws IOException {
|
||||||
@@ -1266,7 +1266,7 @@ public final class JsonReaderTest {
|
|||||||
assertEquals(true, reader.nextBoolean());
|
assertEquals(true, reader.nextBoolean());
|
||||||
reader.beginObject();
|
reader.beginObject();
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void strictMultipleTopLevelValuesWithSkipValue() throws IOException {
|
@Test public void strictMultipleTopLevelValuesWithSkipValue() throws IOException {
|
||||||
@@ -1293,7 +1293,7 @@ public final class JsonReaderTest {
|
|||||||
JsonReader reader = new JsonReader("\"a\"");
|
JsonReader reader = new JsonReader("\"a\"");
|
||||||
reader.setLenient(true);
|
reader.setLenient(true);
|
||||||
assertEquals("a", reader.nextString());
|
assertEquals("a", reader.nextString());
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void strictTopLevelValueType() {
|
@Test public void strictTopLevelValueType() {
|
||||||
@@ -1436,10 +1436,10 @@ public final class JsonReaderTest {
|
|||||||
JsonReader reader = new JsonReader("[0." + repeat('9', 8192) + "]");
|
JsonReader reader = new JsonReader("[0." + repeat('9', 8192) + "]");
|
||||||
reader.setLenient(true);
|
reader.setLenient(true);
|
||||||
reader.beginArray();
|
reader.beginArray();
|
||||||
assertEquals(JsonToken.STRING, reader.peek());
|
assertEquals(JsonReader.Token.STRING, reader.peek());
|
||||||
assertEquals(1d, reader.nextDouble(), 0d);
|
assertEquals(1d, reader.nextDouble(), 0d);
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void veryLongUnquotedLiteral() throws IOException {
|
@Test public void veryLongUnquotedLiteral() throws IOException {
|
||||||
@@ -1463,7 +1463,7 @@ public final class JsonReaderTest {
|
|||||||
for (int i = 0; i < 40; i++) {
|
for (int i = 0; i < 40; i++) {
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
}
|
}
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void deeplyNestedObjects() throws IOException {
|
@Test public void deeplyNestedObjects() throws IOException {
|
||||||
@@ -1485,7 +1485,7 @@ public final class JsonReaderTest {
|
|||||||
for (int i = 0; i < 40; i++) {
|
for (int i = 0; i < 40; i++) {
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
}
|
}
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://code.google.com/p/google-gson/issues/detail?id=409
|
// http://code.google.com/p/google-gson/issues/detail?id=409
|
||||||
@@ -1583,7 +1583,7 @@ public final class JsonReaderTest {
|
|||||||
JsonReader reader = new JsonReader(repeat('x', 8192));
|
JsonReader reader = new JsonReader(repeat('x', 8192));
|
||||||
reader.setLenient(true);
|
reader.setLenient(true);
|
||||||
reader.skipValue();
|
reader.skipValue();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void skipVeryLongQuotedString() throws IOException {
|
@Test public void skipVeryLongQuotedString() throws IOException {
|
||||||
@@ -1597,7 +1597,7 @@ public final class JsonReaderTest {
|
|||||||
JsonReader reader = new JsonReader("\"" + repeat('x', 8192) + "\"");
|
JsonReader reader = new JsonReader("\"" + repeat('x', 8192) + "\"");
|
||||||
reader.setLenient(true);
|
reader.setLenient(true);
|
||||||
reader.skipValue();
|
reader.skipValue();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void stringAsNumberWithTruncatedExponent() throws IOException {
|
@Test public void stringAsNumberWithTruncatedExponent() throws IOException {
|
||||||
@@ -1628,11 +1628,11 @@ public final class JsonReaderTest {
|
|||||||
reader.beginObject();
|
reader.beginObject();
|
||||||
assertEquals(NAME, reader.peek());
|
assertEquals(NAME, reader.peek());
|
||||||
assertEquals("", reader.nextName());
|
assertEquals("", reader.nextName());
|
||||||
assertEquals(JsonToken.BOOLEAN, reader.peek());
|
assertEquals(JsonReader.Token.BOOLEAN, reader.peek());
|
||||||
assertEquals(true, reader.nextBoolean());
|
assertEquals(true, reader.nextBoolean());
|
||||||
assertEquals(JsonToken.END_OBJECT, reader.peek());
|
assertEquals(JsonReader.Token.END_OBJECT, reader.peek());
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
assertEquals(JsonReader.Token.END_DOCUMENT, reader.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void strictExtraCommasInMaps() throws IOException {
|
@Test public void strictExtraCommasInMaps() throws IOException {
|
||||||
@@ -1716,7 +1716,7 @@ public final class JsonReaderTest {
|
|||||||
JsonReader reader = new JsonReader("[\"string");
|
JsonReader reader = new JsonReader("[\"string");
|
||||||
reader.setLenient(true);
|
reader.setLenient(true);
|
||||||
reader.beginArray();
|
reader.beginArray();
|
||||||
assertEquals(JsonToken.STRING, reader.peek());
|
assertEquals(JsonReader.Token.STRING, reader.peek());
|
||||||
try {
|
try {
|
||||||
reader.nextString();
|
reader.nextString();
|
||||||
fail();
|
fail();
|
||||||
|
Reference in New Issue
Block a user