本文整理汇总了Java中com.google.gson.stream.JsonToken类的典型用法代码示例。如果您正苦于以下问题:Java JsonToken类的具体用法?Java JsonToken怎么用?Java JsonToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonToken类属于com.google.gson.stream包,在下文中一共展示了JsonToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: read
import com.google.gson.stream.JsonToken; //导入依赖的package包/类
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);
}
}
示例2: floatAdapter
import com.google.gson.stream.JsonToken; //导入依赖的package包/类
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);
}
};
}
示例3: createJsonReader
import com.google.gson.stream.JsonToken; //导入依赖的package包/类
/** 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);
}
示例4: nullSafe
import com.google.gson.stream.JsonToken; //导入依赖的package包/类
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;
}
};
}
示例5: read
import com.google.gson.stream.JsonToken; //导入依赖的package包/类
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;
}
示例6: read
import com.google.gson.stream.JsonToken; //导入依赖的package包/类
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);
}
示例7: floatAdapter
import com.google.gson.stream.JsonToken; //导入依赖的package包/类
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);
}
};
}
示例8: parse
import com.google.gson.stream.JsonToken; //导入依赖的package包/类
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);
}
}
示例9: read
import com.google.gson.stream.JsonToken; //导入依赖的package包/类
@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);
}
示例10: read
import com.google.gson.stream.JsonToken; //导入依赖的package包/类
@Override
public StringBuilder read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return new StringBuilder(in.nextString());
}
示例11: read
import com.google.gson.stream.JsonToken; //导入依赖的package包/类
public InetAddress read(JsonReader in) throws IOException {
if (in.peek() != JsonToken.NULL) {
return InetAddress.getByName(in.nextString());
}
in.nextNull();
return null;
}
示例12: read
import com.google.gson.stream.JsonToken; //导入依赖的package包/类
@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;
}
}
示例13: read
import com.google.gson.stream.JsonToken; //导入依赖的package包/类
public String read(JsonReader reader) {
try {
if (reader.peek() == JsonToken.NULL) {
reader.nextNull();
return "";//原先是返回Null,这里改为返回空字符串
}
return reader.nextString();
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
示例14: read
import com.google.gson.stream.JsonToken; //导入依赖的package包/类
@Override
public Number read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return (float) in.nextDouble();
}
示例15: deserialize
import com.google.gson.stream.JsonToken; //导入依赖的package包/类
@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;
}
}
}