Java 类com.google.gson.stream.JsonToken 实例源码
项目:boohee_v5.6
文件:ReflectiveTypeAdapterFactory.java
public T read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
T instance = this.constructor.construct();
try {
in.beginObject();
while (in.hasNext()) {
BoundField field = (BoundField) this.boundFields.get(in.nextName());
if (field == null || !field.deserialized) {
in.skipValue();
} else {
field.read(in, instance);
}
}
in.endObject();
return instance;
} catch (Throwable e) {
throw new JsonSyntaxException(e);
} catch (IllegalAccessException e2) {
throw new AssertionError(e2);
}
}
项目:GitHub
文件:GsonMessageBodyProvider.java
/** Forces creation of more strict in string reading if in !lenient mode */
private JsonReader createJsonReader(Reader reader) {
if (!options.lenient) {
return new JsonReader(reader) {
@Override
public String nextString() throws IOException {
JsonToken peeked = peek();
if (peeked == JsonToken.STRING) {
return super.nextString();
}
throw new JsonParseException(
String.format("In strict mode (!lenient) string read only from string literal, not %s. Path: %s",
peeked,
getPath()));
}
};
}
return new JsonReader(reader);
}
项目:boohee_v5.6
文件:TypeAdapter.java
public final TypeAdapter<T> nullSafe() {
return new TypeAdapter<T>() {
public void write(JsonWriter out, T value) throws IOException {
if (value == null) {
out.nullValue();
} else {
TypeAdapter.this.write(out, value);
}
}
public T read(JsonReader reader) throws IOException {
if (reader.peek() != JsonToken.NULL) {
return TypeAdapter.this.read(reader);
}
reader.nextNull();
return null;
}
};
}
项目:boohee_v5.6
文件:Gson.java
private TypeAdapter<Number> floatAdapter(boolean serializeSpecialFloatingPointValues) {
if (serializeSpecialFloatingPointValues) {
return TypeAdapters.FLOAT;
}
return new TypeAdapter<Number>() {
public Float read(JsonReader in) throws IOException {
if (in.peek() != JsonToken.NULL) {
return Float.valueOf((float) in.nextDouble());
}
in.nextNull();
return null;
}
public void write(JsonWriter out, Number value) throws IOException {
if (value == null) {
out.nullValue();
return;
}
Gson.this.checkValidFloatingPoint((double) value.floatValue());
out.value(value);
}
};
}
项目:letv
文件:Gson.java
private TypeAdapter<Number> floatAdapter(boolean serializeSpecialFloatingPointValues) {
if (serializeSpecialFloatingPointValues) {
return TypeAdapters.FLOAT;
}
return new TypeAdapter<Number>() {
public Float read(JsonReader in) throws IOException {
if (in.peek() != JsonToken.NULL) {
return Float.valueOf((float) in.nextDouble());
}
in.nextNull();
return null;
}
public void write(JsonWriter out, Number value) throws IOException {
if (value == null) {
out.nullValue();
return;
}
Gson.this.checkValidFloatingPoint((double) value.floatValue());
out.value(value);
}
};
}
项目:letv
文件:ArrayTypeAdapter.java
public Object read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
List<E> list = new ArrayList();
in.beginArray();
while (in.hasNext()) {
list.add(this.componentTypeAdapter.read(in));
}
in.endArray();
Object array = Array.newInstance(this.componentType, list.size());
for (int i = 0; i < list.size(); i++) {
Array.set(array, i, list.get(i));
}
return array;
}
项目:letv
文件:TypeAdapters.java
public Locale read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
StringTokenizer tokenizer = new StringTokenizer(in.nextString(), EventsFilesManager.ROLL_OVER_FILE_NAME_SEPARATOR);
String language = null;
String country = null;
String variant = null;
if (tokenizer.hasMoreElements()) {
language = tokenizer.nextToken();
}
if (tokenizer.hasMoreElements()) {
country = tokenizer.nextToken();
}
if (tokenizer.hasMoreElements()) {
variant = tokenizer.nextToken();
}
if (country == null && variant == null) {
return new Locale(language);
}
if (variant == null) {
return new Locale(language, country);
}
return new Locale(language, country, variant);
}
项目:letv
文件:ReflectiveTypeAdapterFactory.java
public T read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
T instance = this.constructor.construct();
try {
in.beginObject();
while (in.hasNext()) {
BoundField field = (BoundField) this.boundFields.get(in.nextName());
if (field == null || !field.deserialized) {
in.skipValue();
} else {
field.read(in, instance);
}
}
in.endObject();
return instance;
} catch (Throwable e) {
throw new JsonSyntaxException(e);
} catch (IllegalAccessException e2) {
throw new AssertionError(e2);
}
}
项目:letv
文件:TypeAdapter.java
public final TypeAdapter<T> nullSafe() {
return new TypeAdapter<T>() {
public void write(JsonWriter out, T value) throws IOException {
if (value == null) {
out.nullValue();
} else {
TypeAdapter.this.write(out, value);
}
}
public T read(JsonReader reader) throws IOException {
if (reader.peek() != JsonToken.NULL) {
return TypeAdapter.this.read(reader);
}
reader.nextNull();
return null;
}
};
}
项目:lams
文件:Gson.java
private TypeAdapter<Number> floatAdapter(boolean serializeSpecialFloatingPointValues) {
if (serializeSpecialFloatingPointValues) {
return TypeAdapters.FLOAT;
}
return new TypeAdapter<Number>() {
@Override public Float read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return (float) in.nextDouble();
}
@Override public void write(JsonWriter out, Number value) throws IOException {
if (value == null) {
out.nullValue();
return;
}
float floatValue = value.floatValue();
checkValidFloatingPoint(floatValue);
out.value(value);
}
};
}
项目:boohee_v5.6
文件:JsonParser.java
public JsonElement parse(Reader json) throws JsonIOException, JsonSyntaxException {
try {
JsonReader jsonReader = new JsonReader(json);
JsonElement element = parse(jsonReader);
if (element.isJsonNull() || jsonReader.peek() == JsonToken.END_DOCUMENT) {
return element;
}
throw new JsonSyntaxException("Did not consume the entire document.");
} catch (Throwable e) {
throw new JsonSyntaxException(e);
} catch (Throwable e2) {
throw new JsonIOException(e2);
} catch (Throwable e22) {
throw new JsonSyntaxException(e22);
}
}
项目:GitHub
文件:GsonConverterFactoryTest.java
@Override public AnInterface read(JsonReader jsonReader) throws IOException {
jsonReader.beginObject();
String name = null;
while (jsonReader.peek() != JsonToken.END_OBJECT) {
switch (jsonReader.nextName()) {
case "name":
name = jsonReader.nextString();
break;
}
}
jsonReader.endObject();
return new AnImplementation(name);
}
项目:odoo-work
文件:TypeAdapters.java
@Override
public StringBuilder read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return new StringBuilder(in.nextString());
}
项目:odoo-work
文件:TypeAdapters.java
@Override
public Calendar read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
in.beginObject();
int year = 0;
int month = 0;
int dayOfMonth = 0;
int hourOfDay = 0;
int minute = 0;
int second = 0;
while (in.peek() != JsonToken.END_OBJECT) {
String name = in.nextName();
int value = in.nextInt();
if (YEAR.equals(name)) {
year = value;
} else if (MONTH.equals(name)) {
month = value;
} else if (DAY_OF_MONTH.equals(name)) {
dayOfMonth = value;
} else if (HOUR_OF_DAY.equals(name)) {
hourOfDay = value;
} else if (MINUTE.equals(name)) {
minute = value;
} else if (SECOND.equals(name)) {
second = value;
}
}
in.endObject();
return new GregorianCalendar(year, month, dayOfMonth, hourOfDay, minute, second);
}
项目:boohee_v5.6
文件:TypeAdapters.java
public InetAddress read(JsonReader in) throws IOException {
if (in.peek() != JsonToken.NULL) {
return InetAddress.getByName(in.nextString());
}
in.nextNull();
return null;
}
项目:odoo-work
文件:TypeAdapters.java
@Override
public URL read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
String nextString = in.nextString();
return "null".equals(nextString) ? null : new URL(nextString);
}
项目:boohee_v5.6
文件:TypeAdapters.java
public Character read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
String str = in.nextString();
if (str.length() == 1) {
return Character.valueOf(str.charAt(0));
}
throw new JsonSyntaxException("Expecting character, got: " + str);
}
项目:dds-examples
文件:UnionTypeAdapterFactory.java
@Override
public T read(
final JsonReader in
) throws IOException {
// support null objects
if (in.peek() == JsonToken.NULL) {
// consume object
in.nextNull();
// return null
return null;
}
try {
// try to read union
return readUnion(in);
} catch (Exception e) {
// skip remaining values
while (in.hasNext()) {
in.skipValue();
}
// assert end of object
in.endObject();
// we failed in converting the union
return null;
}
}
项目:boohee_v5.6
文件:TypeAdapters.java
public T read(JsonReader in) throws IOException {
if (in.peek() != JsonToken.NULL) {
return (Enum) this.nameToConstant.get(in.nextString());
}
in.nextNull();
return null;
}
项目:retro2call
文件:CommonJson4List.java
public String read(JsonReader reader) {
try {
if (reader.peek() == JsonToken.NULL) {
reader.nextNull();
return "";//原先是返回Null,这里改为返回空字符串
}
return reader.nextString();
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
项目:lams
文件:TypeAdapters.java
@Override
public Number read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return (float) in.nextDouble();
}
项目:ForgeHax
文件:DimensionProperty.java
@Override
public void deserialize(JsonReader reader) throws IOException {
reader.beginArray();
while(reader.hasNext() && reader.peek().equals(JsonToken.STRING)) {
String dim = reader.nextString();
for(DimensionType type : DimensionType.values()) if(Objects.equals(type.getName(), dim)) {
add(type);
break;
}
}
}
项目:ProjectAres
文件:SemanticVersionTypeAdapter.java
@Override
public SemanticVersion read(JsonReader in) throws IOException {
in.beginArray();
int major = in.nextInt();
int minor = in.nextInt();
int patch = in.peek() == JsonToken.END_ARRAY ? 0 : in.nextInt();
in.endArray();
return new SemanticVersion(major, minor, patch);
}
项目:odoo-work
文件:TypeAdapters.java
@Override
public Character read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
String str = in.nextString();
if (str.length() != 1) {
throw new JsonSyntaxException("Expecting character, got: " + str);
}
return str.charAt(0);
}
项目:odoo-work
文件:TypeAdapters.java
@Override
public String read(JsonReader in) throws IOException {
JsonToken peek = in.peek();
if (peek == JsonToken.NULL) {
in.nextNull();
return null;
}
/* coerce booleans to strings for backwards compatibility */
if (peek == JsonToken.BOOLEAN) {
return Boolean.toString(in.nextBoolean());
}
return in.nextString();
}
项目:odoo-work
文件:TypeAdapters.java
@Override
public InetAddress read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
// regrettably, this should have included both the host name and the host address
return InetAddress.getByName(in.nextString());
}
项目:MCLibrary
文件:ItemStackTypeAdapter.java
@Override
public ItemStack read(JsonReader in) throws IOException {
if (in.peek() != JsonToken.BEGIN_OBJECT)
return null;
int id = 1;
short data = 0;
int amount = 1;
ItemMeta meta = null;
in.beginObject();
while (in.hasNext()) {
String name = in.nextName();
switch (name) {
case "id":
id = in.nextInt();
break;
case "damage":
data = (short) in.nextInt();
break;
case "amount":
amount = in.nextInt();
break;
case "meta":
meta = metaAdapter.read(in);
break;
default:
Static.log("Unknown type, " + name);
}
}
in.endObject();
ItemStack item = new ItemStack(id, amount, data);
if (meta != null)
item.setItemMeta(meta);
return item;
}
项目:lams
文件:JsonTreeReader.java
@Override public int nextInt() throws IOException {
JsonToken token = peek();
if (token != JsonToken.NUMBER && token != JsonToken.STRING) {
throw new IllegalStateException("Expected " + JsonToken.NUMBER + " but was " + token);
}
int result = ((JsonPrimitive) peekStack()).getAsInt();
popStack();
return result;
}
项目:letv
文件:Gson.java
private static void assertFullConsumption(Object obj, JsonReader reader) {
if (obj != null) {
try {
if (reader.peek() != JsonToken.END_DOCUMENT) {
throw new JsonIOException("JSON document was not fully consumed.");
}
} catch (Throwable e) {
throw new JsonSyntaxException(e);
} catch (Throwable e2) {
throw new JsonIOException(e2);
}
}
}
项目:letv
文件:JsonStreamParser.java
public boolean hasNext() {
boolean z;
synchronized (this.lock) {
try {
z = this.parser.peek() != JsonToken.END_DOCUMENT;
} catch (Throwable e) {
throw new JsonSyntaxException(e);
} catch (Throwable e2) {
throw new JsonIOException(e2);
}
}
return z;
}
项目:odoo-work
文件:TypeAdapters.java
@Override public BigInteger read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
try {
return new BigInteger(in.nextString());
} catch (NumberFormatException e) {
throw new JsonSyntaxException(e);
}
}
项目:letv
文件:BigIntegerTypeAdapter.java
public BigInteger read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
try {
return new BigInteger(in.nextString());
} catch (Throwable e) {
throw new JsonSyntaxException(e);
}
}
项目:lams
文件:TypeAdapters.java
@Override
public Number read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
try {
int intValue = in.nextInt();
return (byte) intValue;
} catch (NumberFormatException e) {
throw new JsonSyntaxException(e);
}
}
项目:odoo-work
文件:TypeAdapters.java
@Override
public Number read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
try {
return in.nextLong();
} catch (NumberFormatException e) {
throw new JsonSyntaxException(e);
}
}
项目:cyberduck
文件:JsonBookmarkCollection.java
protected String readNext(final String name, final JsonReader reader) throws IOException {
if(reader.peek() != JsonToken.NULL) {
return reader.nextString();
}
else {
reader.skipValue();
log.warn(String.format("No value for key %s", name));
return null;
}
}
项目:lams
文件:DateTypeAdapter.java
@Override public Date read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return deserializeToDate(in.nextString());
}
项目:boohee_v5.6
文件:TypeAdapters.java
public URL read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
String nextString = in.nextString();
if ("null".equals(nextString)) {
return null;
}
return new URL(nextString);
}
项目:odoo-work
文件:TypeAdapters.java
@Override
public Number read(JsonReader in) throws IOException {
JsonToken jsonToken = in.peek();
switch (jsonToken) {
case NULL:
in.nextNull();
return null;
case NUMBER:
return new LazilyParsedNumber(in.nextString());
default:
throw new JsonSyntaxException("Expecting number, got: " + jsonToken);
}
}
项目:lams
文件:TypeAdapters.java
@Override
public UUID read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return java.util.UUID.fromString(in.nextString());
}
项目:letv
文件:JsonTreeReader.java
public long nextLong() throws IOException {
JsonToken token = peek();
if (token == JsonToken.NUMBER || token == JsonToken.STRING) {
long result = ((JsonPrimitive) peekStack()).getAsLong();
popStack();
return result;
}
throw new IllegalStateException("Expected " + JsonToken.NUMBER + " but was " + token);
}