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:org.eclipse.recommenders.utils.gson.MethodNameTypeAdapter.java

License:Open Source License

@Override
public IMethodName read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();/*  ww  w.ja v  a  2s.  com*/
        return null;
    } else {
        String identifier = in.nextString();
        return VmMethodName.get(identifier);
    }
}

From source file:org.eclipse.recommenders.utils.gson.PackageNameTypeAdapter.java

License:Open Source License

@Override
public IPackageName read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();/*  w  w w.  j a  v a 2  s. co m*/
        return null;
    } else {
        String identifier = in.nextString();
        return VmPackageName.get(identifier);
    }
}

From source file:org.eclipse.recommenders.utils.gson.TypeNameTypeAdapter.java

License:Open Source License

@Override
public ITypeName read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();/*from w  ww  . j av a  2  s.  c  o  m*/
        return null;
    } else {
        String identifier = in.nextString();
        return VmTypeName.get(identifier);
    }
}

From source file:org.eclipse.smarthome.persistence.mapdb.internal.StateTypeAdapter.java

License:Open Source License

@Override
public State read(JsonReader reader) throws IOException {
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();//  ww w.  j av a2s.c  o m
        return null;
    }
    String value = reader.nextString();
    String[] parts = value.split(TYPE_SEPARATOR);
    String valueTypeName = parts[0];
    String valueAsString = parts[1];

    try {
        @SuppressWarnings("unchecked")
        Class<? extends State> valueType = (Class<? extends State>) Class.forName(valueTypeName);
        List<Class<? extends State>> types = Collections.singletonList(valueType);
        return TypeParser.parseState(types, valueAsString);
    } catch (Exception e) {
        logger.warn("Couldn't deserialize state '{}': {}", value, e.getMessage());
    }
    return null;
}

From source file:org.eclipse.smarthome.storage.json.PropertiesTypeAdapter.java

License:Open Source License

private Object getValue(JsonReader in) throws IOException {
    Object value = null;/*from  w  w w.  j a  v a  2s  .  c o  m*/

    // if the next json token is a number we read it as a BigDecimal,
    // otherwise use the default adapter to read it
    if (JsonToken.NUMBER.equals(in.peek())) {
        String inString = in.nextString();
        if (inString.endsWith(".0")) {
            value = new BigDecimal(inString).setScale(0);
        } else {
            value = new BigDecimal(inString);
        }
    } else {
        value = valueAdapter.read(in);
    }

    return value;

}

From source file:org.eclipse.smarthome.storage.mapdb.internal.PropertiesTypeAdapter.java

License:Open Source License

private Object getValue(JsonReader in) throws IOException {
    Object value = null;//ww w. java2  s .  c  om

    // if the next json token is a number we read it as a BigDecimal,
    // otherwise use the default adapter to read it
    if (JsonToken.NUMBER.equals(in.peek())) {
        value = new BigDecimal(in.nextString());
    } else {
        value = valueAdapter.read(in);
    }

    return value;
}

From source file:org.eclipse.smarthome.storage.mapdb.PropertiesTypeAdapter.java

License:Open Source License

private Object getValue(JsonReader in) throws IOException {
    Object value = null;//ww  w  . ja  v a2  s.  c o m

    // if the next json token is a number we read it as a BigDecimal,
    // otherwise use the default adapter to read it
    if (JsonToken.NUMBER.equals(in.peek())) {
        value = new BigDecimal(in.nextString());
    } else {
        value = valueAdapter.read(in);
    }

    return value;

}

From source file:org.eclipse.thym.core.plugin.registry.CordovaPluginRegistryManager.java

License:Open Source License

private CordovaRegistryPluginInfo parseCordovaRegistryPluginInfo(JsonReader reader) throws IOException {
    CordovaRegistryPluginInfo info = new CordovaRegistryPluginInfo();
    reader.beginObject();//  w  w w  . j  a  va  2  s.  c o m
    reader.skipValue(); // name
    reader.beginArray();
    reader.nextString(); //ecosystem:cordova
    info.setName(safeReadStringValue(reader));
    info.setDescription(safeReadStringValue(reader));
    reader.endArray();
    reader.nextName();
    reader.nextInt();
    reader.endObject();
    return info;
}

From source file:org.eclipse.thym.core.plugin.registry.CordovaPluginRegistryManager.java

License:Open Source License

private String safeReadStringValue(JsonReader reader) throws IOException {
    if (reader.peek() == JsonToken.STRING) {
        return reader.nextString();
    }//from   w  w w  .j  a  va2s. co  m
    reader.skipValue();
    return "";
}

From source file:org.eclipse.thym.core.plugin.registry.CordovaPluginRegistryManager.java

License:Open Source License

private void readPluginInfo(JsonReader reader, CordovaRegistryPlugin plugin) throws IOException {
    Assert.isNotNull(plugin);//w  ww  . j ava2s . c  o  m
    reader.beginObject();

    while (reader.hasNext()) {
        JsonToken token = reader.peek();
        switch (token) {
        case NAME: {
            String name = reader.nextName();
            if ("name".equals(name)) {
                plugin.setName(reader.nextString());
                break;
            }
            if ("description".equals(name)) {
                plugin.setDescription(reader.nextString());
                break;
            }
            if ("keywords".equals(name)) {
                parseKeywords(reader, plugin);
                break;
            }
            if ("maintainers".equals(name)) {
                parseMaintainers(reader, plugin);
                break;
            }
            if ("dist-tags".equals(name)) {
                parseLatestVersion(reader, plugin);
                break;
            }
            if ("versions".equals(name)) {
                parseVersions(reader, plugin);
                break;
            }
            if ("license".equals(name)) {
                plugin.setLicense(reader.nextString());
                break;
            }
            break;
        }

        default:
            reader.skipValue();
            break;
        }
    }
    reader.endObject();
}