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

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

Introduction

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

Prototype

public String nextString() throws IOException 

Source Link

Document

Returns the com.google.gson.stream.JsonToken#STRING string value of the next token, consuming it.

Usage

From source file:DateTimeTypeAdapter.java

License:Apache License

@Override
public DateTime read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();//www  .j av  a2  s .co m
        return null;
    }
    return new DateTime(in.nextString());
}

From source file:DurationTypeAdapter.java

License:Apache License

@Override
public Duration read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();//ww  w  .  j av a  2 s  . c  om
        return null;
    }
    return new Duration(in.nextString());
}

From source file:TemporalTypeAdapter.java

License:Apache License

@Override
public T read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();//from  w  w  w .  j a v a  2 s. c  o  m
        return null;
    }
    String temporalString = preProcess(in.nextString());
    return parseFunction.apply(temporalString);
}

From source file:IntervalTypeAdapter.java

License:Apache License

@Override
public Interval read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();/*from  ww  w . j av a 2s .  c om*/
        return null;
    }
    return new Interval(in.nextString());
}

From source file:abtlibrary.utils.as24ApiClient.JSON.java

License:Apache License

@Override
public DateTime read(JsonReader in) throws IOException {
    switch (in.peek()) {
    case NULL:/*w w  w  .  j  a  va  2s  .  com*/
        in.nextNull();
        return null;
    default:
        String date = in.nextString();
        return formatter.parseDateTime(date.substring(0, date.indexOf("Z")) + ".000Z");
    }
}

From source file:abtlibrary.utils.as24ApiClient.JSON.java

License:Apache License

@Override
public LocalDate read(JsonReader in) throws IOException {
    switch (in.peek()) {
    case NULL:/*  w  w  w.  j a v  a  2s  .c o  m*/
        in.nextNull();
        return null;
    default:
        String date = in.nextString();
        return formatter.parseLocalDate(date);
    }
}

From source file:at.univie.sensorium.preferences.Preferences.java

License:Open Source License

private void loadPrefsFromStream(InputStream input) {
    List<BasicNameValuePair> preferencelist = new LinkedList<BasicNameValuePair>();
    try {/* w  w  w . j av a2 s . c  o  m*/
        InputStreamReader isreader = new InputStreamReader(input);
        JsonReader reader = new JsonReader(isreader);
        //         String jsonVersion = "";

        reader.beginArray(); // do we have an array or just a single object?
        reader.beginObject();
        while (reader.hasNext()) {
            String name = reader.nextName();
            String value = reader.nextString();
            if (name.equalsIgnoreCase(PREFERENCES_VERSION))
                currentPrefVersion = Integer.valueOf(value);
            BasicNameValuePair kv = new BasicNameValuePair(name, value);
            preferencelist.add(kv);
        }
        reader.endObject();
        reader.endArray();
        reader.close();

        if (newerPrefsAvailable()) {
            Log.d(SensorRegistry.TAG, "Newer preferences available in json, overwriting existing.");
            for (BasicNameValuePair kv : preferencelist) {
                putPreference(kv.getName(), kv.getValue());
            }
            // also reset the welcome screen
            putBoolean(WELCOME_SCREEN_SHOWN, false);
        } else {
            Log.d(SensorRegistry.TAG, "Preferences are recent, not overwriting.");
        }

    } catch (FileNotFoundException e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        Log.d(SensorRegistry.TAG, sw.toString());
    } catch (IOException e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        Log.d(SensorRegistry.TAG, sw.toString());
    }
}

From source file:at.yawk.mojangapi.UUIDTypeAdapter.java

License:Mozilla Public License

@Override
public UUID read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        return null;
    } else {//from  ww  w .j ava  2s .  co m
        StringBuilder s = new StringBuilder(in.nextString());
        s.insert(8 + 4 * 3, '-');
        s.insert(8 + 4 * 2, '-');
        s.insert(8 + 4, '-');
        s.insert(8, '-');
        return UUID.fromString(s.toString());
    }
}

From source file:blog.ClassTypeAdapter.java

License:Apache License

@Override
public Class<?> read(JsonReader jsonReader) throws IOException {
    if (jsonReader.peek() == JsonToken.NULL) {
        jsonReader.nextNull();/*from  www  .  ja v  a  2  s .c  om*/
        return null;
    }
    Class<?> clazz;
    try {
        clazz = Class.forName(jsonReader.nextString());
    } catch (ClassNotFoundException exception) {
        throw new IOException(exception);
    }
    return clazz;
}

From source file:br.com.caelum.restfulie.gson.converters.DateTypeAdapter.java

License:Apache License

@Override
public Date read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();/*from   ww  w .  j a v a2s.c  o m*/
        return null;
    }
    return deserializeToDate(in.nextString());
}