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

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

Introduction

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

Prototype

public void nextNull() throws IOException 

Source Link

Document

Consumes the next token from the JSON stream and asserts that it is a literal null.

Usage

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;// w  w w  . j a  v  a2  s  .c  o m
    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;/*w  w  w .  ja  va2 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  ww .j  a v  a  2  s  .co 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;/*  w w w  . j  ava2s . 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
 */// w  ww .  j  a va2s  .  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;/*w ww .j a v a2 s  . co m*/
    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;// w  w w .  java 2 s  .co 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  w  w  .j a v a  2  s  .  com*/
    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;//  w  ww . ja  v  a 2s .c  om
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();
    } else {
        value = reader.nextString();
    }
    return value;
}

From source file:org.sprintapi.hyperdata.gson.HyperDataTypeAdapter.java

License:Apache License

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override//from   w w w  .j av a  2 s. co  m
public Object read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
    }

    Object instance = constructor.construct();

    BoundField metadataField = null;
    if (metadataAccess != null) {
        metadataField = boundFields.get(metadataAccess.fieldName);
    }

    Object meta = null;
    Map<String, BoundField> metaBoundFields = null;

    try {
        in.beginObject();
        while (in.hasNext()) {
            String name = in.nextName();
            if ((name != null) && (metadataField != null) && (name.startsWith(Constants.META_CHAR))) {
                if (meta == null) {
                    meta = constructorConstructor.get(metadataField.type).construct();
                    if (!Map.class.isAssignableFrom(meta.getClass())) {
                        metaBoundFields = reflectiveFactory.getBoundFields(gson, metadataField.type,
                                metadataField.type.getRawType());
                    }
                }

                if (metaBoundFields != null) {
                    BoundField field = metaBoundFields.get(name.substring(1));
                    if (field == null || !field.deserialized) {
                        in.skipValue();
                    } else {
                        field.read(in, meta);
                    }
                } else {
                    TypeAdapter<Object> ta = gson.getAdapter(Object.class);
                    Object value = ta.read(in);
                    ((Map) meta).put(name.substring(1), value);
                }

            } else if ((name != null) && (!name.equals(metadataAccess.fieldName))) {
                BoundField field = boundFields.get(name);
                if (field == null || !field.deserialized) {
                    in.skipValue();
                } else {
                    field.read(in, instance);
                }
            }
        }
        if (metadataAccess.setter != null) {
            metadataAccess.setter.invoke(instance, meta);
            //TODO
        }

    } catch (IllegalStateException e) {
        throw new JsonSyntaxException(e);
    } catch (IllegalAccessException e) {
        throw new AssertionError(e);
    } catch (IllegalArgumentException e) {
        throw new AssertionError(e);
    } catch (InvocationTargetException e) {
        throw new AssertionError(e);
    }
    in.endObject();
    return instance;
}