当前位置: 首页>>代码示例>>Java>>正文


Java JsonReader.peek方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:20,代码来源:Streams.java

示例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);
    }
  };
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:Gson.java

示例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);
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:25,代码来源:Gson.java

示例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();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:TypeAdapters.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:8,代码来源:TypeAdapters.java

示例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;
}
 
开发者ID:LightSun,项目名称:data-mediator,代码行数:29,代码来源:Car3TypeAdapter.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:14,代码来源:CollectionTypeAdapterFactory.java

示例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);
    }
}
 
开发者ID:cliffano,项目名称:swaggy-jenkins,代码行数:15,代码来源:JSON.java

示例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);
  }
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:12,代码来源:TypeAdapters.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:8,代码来源:TypeAdapters.java

示例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;
}
 
开发者ID:LightSun,项目名称:data-mediator,代码行数:16,代码来源:ListCar3TypeAdapter.java

示例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);
    }
}
 
开发者ID:caeos,项目名称:coner-core-client-java,代码行数:12,代码来源:JSON.java

示例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());
                }
            }
        };
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:48,代码来源:EnumTypeAdapterFactory.java

示例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();
        }
    };
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:48,代码来源:AnimationStateMachine.java


注:本文中的com.google.gson.stream.JsonReader.peek方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。