本文整理汇总了Java中com.google.gson.stream.JsonReader.peek方法的典型用法代码示例。如果您正苦于以下问题:Java JsonReader.peek方法的具体用法?Java JsonReader.peek怎么用?Java JsonReader.peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.stream.JsonReader
的用法示例。
在下文中一共展示了JsonReader.peek方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public static JsonElement parse(JsonReader reader) throws JsonParseException {
boolean isEmpty = true;
try {
reader.peek();
isEmpty = false;
return (JsonElement) TypeAdapters.JSON_ELEMENT.read(reader);
} catch (Throwable e) {
if (isEmpty) {
return JsonNull.INSTANCE;
}
throw new JsonSyntaxException(e);
} catch (Throwable e2) {
throw new JsonSyntaxException(e2);
} catch (Throwable e22) {
throw new JsonIOException(e22);
} catch (Throwable e222) {
throw new JsonSyntaxException(e222);
}
}
示例2: doubleAdapter
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
private TypeAdapter<Number> doubleAdapter(boolean serializeSpecialFloatingPointValues) {
if (serializeSpecialFloatingPointValues) {
return TypeAdapters.DOUBLE;
}
return new TypeAdapter<Number>() {
@Override public Double read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return in.nextDouble();
}
@Override public void write(JsonWriter out, Number value) throws IOException {
if (value == null) {
out.nullValue();
return;
}
double doubleValue = value.doubleValue();
checkValidFloatingPoint(doubleValue);
out.value(value);
}
};
}
示例3: fromJson
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public <T> T fromJson(JsonReader reader, Type typeOfT) throws JsonIOException, JsonSyntaxException {
boolean isEmpty = true;
boolean oldLenient = reader.isLenient();
reader.setLenient(true);
try {
reader.peek();
isEmpty = false;
T read = getAdapter(TypeToken.get(typeOfT)).read(reader);
reader.setLenient(oldLenient);
return read;
} catch (Throwable e) {
if (isEmpty) {
reader.setLenient(oldLenient);
return null;
}
throw new JsonSyntaxException(e);
} catch (Throwable e2) {
throw new JsonSyntaxException(e2);
} catch (Throwable e22) {
throw new JsonSyntaxException(e22);
} catch (Throwable th) {
reader.setLenient(oldLenient);
}
}
示例4: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public Number read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return in.nextDouble();
}
示例5: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public Number read(JsonReader in) throws IOException {
if (in.peek() != JsonToken.NULL) {
return Double.valueOf(in.nextDouble());
}
in.nextNull();
return null;
}
示例6: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public Car3 read(JsonReader reader) throws IOException {
Car3 car = new Car3();
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
if (name.equals("mark")) {
car.setMark(reader.nextString());
} else if (name.equals("model")) {
car.setModel(reader.nextInt());
} else if (name.equals("type")) {
car.setType(reader.nextString());
} else if (name.equals("maker")) {
car.setType(reader.nextString());
} else if (name.equals("cost")) {
double cost = reader.nextDouble();
double costExcludingVAT = cost / 1.21;
car.setCost(costExcludingVAT); //Remove VAT 21%
} else if (name.equals("colors") && reader.peek() != JsonToken.NULL) {
car.setColors(readStringArray(reader));
} else {
reader.skipValue();
}
}
reader.endObject();
return car;
}
示例7: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public Collection<E> read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
Collection<E> collection = (Collection) this.constructor.construct();
in.beginArray();
while (in.hasNext()) {
collection.add(this.elementTypeAdapter.read(in));
}
in.endArray();
return collection;
}
示例8: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public OffsetDateTime read(JsonReader in) throws IOException {
switch (in.peek()) {
case NULL:
in.nextNull();
return null;
default:
String date = in.nextString();
if (date.endsWith("+0000")) {
date = date.substring(0, date.length()-5) + "Z";
}
return OffsetDateTime.parse(date, formatter);
}
}
示例9: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override public BigDecimal read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
try {
return new BigDecimal(in.nextString());
} catch (NumberFormatException e) {
throw new JsonSyntaxException(e);
}
}
示例10: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public StringBuilder read(JsonReader in) throws IOException {
if (in.peek() != JsonToken.NULL) {
return new StringBuilder(in.nextString());
}
in.nextNull();
return null;
}
示例11: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public List<Car3> read(JsonReader in) throws IOException {
List<Car3> list = new ArrayList<>();
in.beginArray();
while (in.hasNext()){
switch (in.peek()){
case BEGIN_OBJECT:
// log("BEGIN_OBJECT");
list.add(mAdapter.read(in));
break;
}
}
in.endArray();
return list;
}
示例12: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public DateTime read(JsonReader in) throws IOException {
switch (in.peek()) {
case NULL:
in.nextNull();
return null;
default:
String date = in.nextString();
return parseFormatter.parseDateTime(date);
}
}
示例13: create
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Nullable
public <T> TypeAdapter<T> create(Gson p_create_1_, TypeToken<T> p_create_2_)
{
Class<T> oclass = (Class<T>)p_create_2_.getRawType();
if (!oclass.isEnum())
{
return null;
}
else
{
final Map<String, T> map = Maps.<String, T>newHashMap();
for (T t : oclass.getEnumConstants())
{
map.put(this.getName(t), t);
}
return new TypeAdapter<T>()
{
public void write(JsonWriter p_write_1_, T p_write_2_) throws IOException
{
if (p_write_2_ == null)
{
p_write_1_.nullValue();
}
else
{
p_write_1_.value(EnumTypeAdapterFactory.this.getName(p_write_2_));
}
}
@Nullable
public T read(JsonReader p_read_1_) throws IOException
{
if (p_read_1_.peek() == JsonToken.NULL)
{
p_read_1_.nextNull();
return (T)null;
}
else
{
return (T)map.get(p_read_1_.nextString());
}
}
};
}
}
示例14: create
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type)
{
if(type.getRawType() != ImmutableMultimap.class || !(type.getType() instanceof ParameterizedType))
{
return null;
}
final Type[] typeArguments = ((ParameterizedType) type.getType()).getActualTypeArguments();
if(typeArguments.length != 2 || typeArguments[0] != String.class || typeArguments[1] != String.class)
{
return null;
}
final TypeAdapter<Map<String, Collection<String>>> mapAdapter = gson.getAdapter(new TypeToken<Map<String, Collection<String>>>(){});
final TypeAdapter<Collection<String>> collectionAdapter = gson.getAdapter(new TypeToken<Collection<String>>(){});
return (TypeAdapter<T>)new TypeAdapter<ImmutableMultimap<String, String>>()
{
@Override
public void write(JsonWriter out, ImmutableMultimap<String, String> value) throws IOException
{
mapAdapter.write(out, value.asMap());
}
@Override
public ImmutableMultimap<String, String> read(JsonReader in) throws IOException
{
ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder();
in.beginObject();
while(in.hasNext())
{
String key = in.nextName();
switch(in.peek())
{
case STRING:
builder.put(key, in.nextString());
break;
case BEGIN_ARRAY:
builder.putAll(key, collectionAdapter.read(in));
break;
default:
throw new JsonParseException("Expected String or Array, got " + in.peek());
}
}
in.endObject();
return builder.build();
}
};
}