Example usage for com.google.gson.stream JsonReader peek

List of usage examples for com.google.gson.stream JsonReader peek

Introduction

In this page you can find the example usage for com.google.gson.stream JsonReader peek.

Prototype

public JsonToken peek() throws IOException 

Source Link

Document

Returns the type of the next token without consuming it.

Usage

From source file:org.openqa.selenium.json.Json.java

License:Apache License

private static Object readValue(JsonReader in, Gson gson) throws IOException {
    switch (in.peek()) {
    case BEGIN_ARRAY:
    case BEGIN_OBJECT:
    case BOOLEAN:
    case NULL:// ww  w  .  j a v a  2  s  .c  o  m
    case STRING:
        return gson.fromJson(in, Object.class);

    case NUMBER:
        String number = in.nextString();
        if (number.indexOf('.') != -1) {
            return Double.parseDouble(number);
        }
        return Long.parseLong(number);

    default:
        throw new JsonParseException("Unexpected type: " + in.peek());
    }
}

From source file:org.openstreetmap.josm.plugins.openstreetcam.service.photo.adapter.ReaderUtil.java

License:LGPL

static Double readDouble(final JsonReader reader) throws IOException {
    Double value = null;//from  www  .j  a v  a2  s .  c om
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();
    } else {
        value = reader.nextDouble();
    }
    return value;
}

From source file:org.openstreetmap.josm.plugins.openstreetcam.service.photo.adapter.ReaderUtil.java

License:LGPL

static Long readLong(final JsonReader reader) throws IOException {
    Long value = null;/*from w ww.jav  a  2 s  .c  o  m*/
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();
    } else {
        value = reader.nextLong();
    }
    return value;
}

From source file:org.openstreetmap.josm.plugins.openstreetcam.service.photo.adapter.ReaderUtil.java

License:LGPL

static Integer readInt(final JsonReader reader) throws IOException {
    Integer value = null;//  w w  w.  java  2 s  .  c  o  m
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();
    } else {
        value = reader.nextInt();
    }
    return value;
}

From source file:org.openstreetmap.josm.plugins.openstreetcam.service.photo.adapter.ReaderUtil.java

License:LGPL

static String readString(final JsonReader reader) throws IOException {
    String value = null;/*from w  ww . j av a 2  s. c  om*/
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();
    } else {
        value = reader.nextString();
    }
    return value;
}

From source file:org.openstreetmap.josm.plugins.openstreetcam.service.photo.adapter.ReaderUtil.java

License:LGPL

/**
 * Reads a geometry that has the following format: [[lat1,lon1], [lat2,lon2],...[latn,lonn]].
 *
 * @param reader a {@code JsonReader} object
 * @return a list of {@code LatLon} objects
 * @throws IOException if the read operation failed
 *//*from w  w w  .  j a  v  a 2  s  .  c  o  m*/
static List<LatLon> readGeometry(final JsonReader reader) throws IOException {
    final List<LatLon> geometry = new ArrayList<>();
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();
    } else {
        reader.beginArray();
        while (reader.hasNext()) {
            reader.beginArray();
            final Double lat = reader.nextDouble();
            final Double lon = reader.nextDouble();
            geometry.add(new LatLon(lat, lon));
            reader.endArray();
        }
        reader.endArray();
    }
    return geometry;
}

From source file:org.openstreetmap.josm.plugins.openstreetcam.service.PhotoTypeAdapter.java

License:Apache License

private Double readDouble(final JsonReader reader) throws IOException {
    Double value = null;/*from   w  w  w . ja  v a2s.c om*/
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();
    } else {
        value = reader.nextDouble();
    }
    return value;
}

From source file:org.openstreetmap.josm.plugins.openstreetcam.service.PhotoTypeAdapter.java

License:Apache License

private Long readLong(final JsonReader reader) throws IOException {
    Long value = null;//from   w w  w  .jav a  2 s. c o m
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();
    } else {
        value = reader.nextLong();
    }
    return value;
}

From source file:org.openstreetmap.josm.plugins.openstreetcam.service.PhotoTypeAdapter.java

License:Apache License

private Integer readInt(final JsonReader reader) throws IOException {
    Integer value = null;//from  w ww .jav a  2  s  .  c o  m
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();
    } else {
        value = reader.nextInt();
    }
    return value;
}

From source file:org.openstreetmap.josm.plugins.openstreetcam.service.PhotoTypeAdapter.java

License:Apache License

private String readString(final JsonReader reader) throws IOException {
    String value = null;//from ww  w.j a va 2 s . c  om
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();
    } else {
        value = reader.nextString();
    }
    return value;
}