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:de.dentrassi.pm.maven.ByteArrayAdapter.java

License:Open Source License

@Override
public byte[] read(final JsonReader reader) throws IOException {
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();
        return null;
    }//w ww.  j  ava2s . co m

    final String data = reader.nextString();

    return Base64.getDecoder().decode(data);
}

From source file:de.feike.tiingoclient.JSON.java

License:Apache License

@Override
public DateTime read(JsonReader in) throws IOException {
    switch (in.peek()) {
    case NULL://from   w  w  w  . j  a  va  2  s . c o  m
        in.nextNull();
        return null;
    default:
        String date = in.nextString();
        return parseFormatter.parseDateTime(date);
    }
}

From source file:de.innovationgate.utils.GsonUtils.java

License:Open Source License

/**
 * Reads the next string value from the reader or null if it is a null value
 * @param reader The reader//from w  w w.ja v  a2s  . c  o m
 * @return String value or null
 * @throws IOException
 */
public static String nextStringOrNull(JsonReader reader) throws IOException {
    if (reader.peek() != JsonToken.NULL) {
        return reader.nextString();
    } else {
        reader.nextNull();
        return null;
    }
}

From source file:de.innovationgate.utils.GsonUtils.java

License:Open Source License

/**
 * Reads the next string value from the reader or null if it is a null value
 * @param reader The reader/*from ww  w. j a  v a  2 s.  c  o  m*/
 * @return Boolean value or null
 * @throws IOException
 */
public static Boolean nextBooleanOrNull(JsonReader reader) throws IOException {
    if (reader.peek() != JsonToken.NULL) {
        return reader.nextBoolean();
    } else {
        reader.nextNull();
        return null;
    }
}

From source file:de.innovationgate.utils.GsonUtils.java

License:Open Source License

/**
 * Reads the next double value from the reader or null if it is a null value
 * @param reader The reader/*from   w w  w . j  a  v a  2s .  com*/
 * @return Double value or null
 * @throws IOException
 */
public static Double nextDoubleOrNull(JsonReader reader) throws IOException {
    if (reader.peek() != JsonToken.NULL) {
        return reader.nextDouble();
    } else {
        reader.nextNull();
        return null;
    }
}

From source file:de.innovationgate.utils.GsonUtils.java

License:Open Source License

/**
 * Reads the next integer value from the reader or null if it is a null value
 * @param reader The reader// w  ww .j  a  va2 s  .  c o  m
 * @return Integer value or null
 * @throws IOException
 */
public static Integer nextIntegerOrNull(JsonReader reader) throws IOException {
    if (reader.peek() != JsonToken.NULL) {
        return reader.nextInt();
    } else {
        reader.nextNull();
        return null;
    }
}

From source file:de.innovationgate.utils.GsonUtils.java

License:Open Source License

/**
 * Reads the next long value from the reader or null if it is a null value
 * @param reader The reader// w w w.ja v  a 2 s  . c  o  m
 * @return Long value or null
 * @throws IOException
 */
public static Long nextLongOrNull(JsonReader reader) throws IOException {
    if (reader.peek() != JsonToken.NULL) {
        return reader.nextLong();
    } else {
        reader.nextNull();
        return null;
    }
}

From source file:de.m0ep.canvas.gson.ISO8601TypeAdapter.java

License:Open Source License

@Override
public Date read(JsonReader reader) throws IOException {
    if (JsonToken.NULL == reader.peek()) {
        reader.nextNull();
        return null;
    }//from  ww w. j a  v  a 2  s . c om

    String date = reader.nextString();
    Calendar cal = DatatypeConverter.parseDateTime(date);
    return cal.getTime();
}

From source file:es.alrocar.poiproxy.fiware.poidp.schema.utils.DateTypeAdapter.java

License:Apache License

@Override
public Date read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
    }/* w  ww. java2s. c  o m*/

    String result = in.nextString();
    if (result.isEmpty()) {
        return null;
    }
    Date date = DateUtil.stringToDate(result);
    return date;
}

From source file:eu.jtzipi.project0.common.json.impl.GsonReadWrite.java

License:Apache License

static Collection<Object> parseArray(final JsonReader jsonReader) throws IOException {
    assert null != jsonReader : "DEBUG: The json Reader is null";

    Collection<Object> l = new ArrayList<>();
    JsonToken tok;//  ww  w  .j a  va 2 s.co  m

    //
    while (jsonReader.hasNext()) {

        tok = jsonReader.peek();
        // we reach the end of this array
        if (JsonToken.END_ARRAY == tok) {
            jsonReader.endArray();
            // return
            break;
        }
        // what token
        switch (tok) {
        // if array/map - parse and append
        case BEGIN_ARRAY:
            l.add(parseArray(jsonReader));
            break;
        case BEGIN_OBJECT:
            l.add(parseObject(jsonReader));
            break;
        // if raw type
        case STRING:
            l.add(jsonReader.nextString());
            break;
        case BOOLEAN:
            l.add(jsonReader.nextBoolean());
            break;
        case NUMBER:
            l.add(jsonReader.nextDouble());
            break;
        // if null , add null and consume
        case NULL:
            l.add(null);
            jsonReader.nextNull();
            break;

        // all other cases are errors
        default:
            throw new IllegalStateException("Wrong Token '" + tok + "' , while parsing an array");
        }
    }

    return l;
}