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

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

Introduction

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

Prototype

public void skipValue() throws IOException 

Source Link

Document

Skips the next value recursively.

Usage

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

License:Open Source License

private void parseVersions(JsonReader reader, CordovaRegistryPlugin plugin) throws IOException {
    reader.beginObject();//versions
    JsonToken token = reader.peek();//  w  w  w.  j  av  a 2 s .c  o  m
    while (token != JsonToken.END_OBJECT) {
        switch (token) {
        case NAME:
            RegistryPluginVersion version = plugin.new RegistryPluginVersion();
            version.setVersionNumber(reader.nextName());
            readVersionInfo(reader, version);
            plugin.addVersion(version);
            break;

        default:
            reader.skipValue();
            break;
        }
        token = reader.peek();
    }
    reader.endObject();
}

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

License:Open Source License

private void parseLatestVersion(JsonReader reader, CordovaRegistryPlugin plugin) throws IOException {
    reader.beginObject();//from  ww  w  .  ja va2  s . c o m
    JsonToken token = reader.peek();
    while (token != JsonToken.END_OBJECT) {
        switch (token) {
        case NAME:
            String tag = reader.nextName();
            if ("latest".equals(tag)) {
                plugin.setLatestVersion(reader.nextString());
            }
            break;

        default:
            reader.skipValue();
            break;
        }
        token = reader.peek();
    }
    reader.endObject();
}

From source file:org.fao.fenix.wds.core.datasource.DatasourcePool.java

License:Open Source License

/**
 * @param reader    Google's <code>JsonReader</code>
 * @return <code>DatasourceBean</code> populated out of the JSON file
 * @throws IOException/*from  ww w . j av  a2 s  .  c  om*/
 *
 * This method reads one of the objects of the JSON array through the
 * <code>JsonReader</code> and creates a <code>DatasourceBean</code>
 * out of it.
 */
public DatasourceBean readMessage(JsonReader reader) throws IOException {
    DatasourceBean b = new DatasourceBean();
    reader.beginObject();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equalsIgnoreCase("driver")) {
            DRIVER d = DRIVER.valueOf(reader.nextString().toUpperCase());
            b.setDriver(d);
        } else if (name.equalsIgnoreCase("id")) {
            b.setId(reader.nextString());
        } else if (name.equalsIgnoreCase("url")) {
            b.setUrl(reader.nextString());
        } else if (name.equalsIgnoreCase("dbName")) {
            b.setDbName(reader.nextString());
        } else if (name.equalsIgnoreCase("username")) {
            b.setUsername(reader.nextString());
        } else if (name.equalsIgnoreCase("password")) {
            b.setPassword(reader.nextString());
        } else if (name.equalsIgnoreCase("create")) {
            b.setCreate(reader.nextBoolean());
        } else if (name.equalsIgnoreCase("retrieve")) {
            b.setRetrieve(reader.nextBoolean());
        } else if (name.equalsIgnoreCase("update")) {
            b.setUpdate(reader.nextBoolean());
        } else if (name.equalsIgnoreCase("delete")) {
            b.setDelete(reader.nextBoolean());
        } else {
            reader.skipValue();
        }
    }
    reader.endObject();
    return b;
}

From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.ModuleMetadataParser.java

License:Apache License

private void consumeAny(JsonReader reader) throws IOException {
    reader.skipValue();
}

From source file:org.gradle.nativeplatform.toolchain.internal.msvcpp.version.CommandLineToolVersionLocator.java

License:Apache License

private VisualStudioInstallCandidate readInstall(JsonReader reader) throws IOException {
    String visualStudioInstallPath = null;
    String visualStudioVersion = null;

    reader.beginObject();/*w  w w.  j ava  2  s. co  m*/
    while (reader.hasNext()) {
        String key = reader.nextName();
        if (key.equals(INSTALLATION_PATH_KEY)) {
            visualStudioInstallPath = reader.nextString();
        } else if (key.equals(INSTALLATION_VERSION_KEY)) {
            visualStudioVersion = reader.nextString();
        } else {
            reader.skipValue();
        }
    }
    reader.endObject();

    File visualStudioInstallDir = new File(visualStudioInstallPath);
    VisualCppInstallCandidate visualCppMetadata = findVisualCppMetadata(visualStudioInstallDir,
            visualStudioVersion);

    if (visualCppMetadata == null) {
        LOGGER.debug("Ignoring candidate Visual Studio version " + visualStudioVersion + " at "
                + visualStudioInstallPath + " because it does not appear to be a valid installation");
        return null;
    } else {
        return new VisualStudioMetadataBuilder().installDir(visualStudioInstallDir)
                .visualCppDir(visualCppMetadata.getVisualCppDir())
                .version(VersionNumber.parse(visualStudioVersion))
                .visualCppVersion(visualCppMetadata.getVersion()).build();
    }
}

From source file:org.guvnor.ala.openshift.access.OpenShiftRuntimeId.java

License:Apache License

public static OpenShiftRuntimeId fromString(String s) {
    String project = null;/*from  ww w .  j  av a  2s .  co  m*/
    String service = null;
    String application = null;
    try {
        JsonReader jr = new JsonReader(new StringReader(s));
        jr.beginObject();
        while (jr.hasNext()) {
            String n = jr.nextName();
            if (PROJECT.equals(n)) {
                project = jr.nextString();
            } else if (SERVICE.equals(n)) {
                service = jr.nextString();
            } else if (APPLICATION.equals(n)) {
                application = jr.nextString();
            } else {
                jr.skipValue();
            }
        }
        jr.endObject();
        jr.close();
    } catch (IOException ex) {
        throw new RuntimeException(ex.getMessage(), ex);
    }
    return new OpenShiftRuntimeId(project, service, application);
}

From source file:org.hibernate.search.elasticsearch.util.impl.gson.ES2FieldDataTypeJsonAdapter.java

License:LGPL

@Override
public FieldDataType read(JsonReader in) throws IOException {
    // Ignore: fielddata is not supported on ES2
    in.skipValue();
    return null;/*w  ww .  j  a  va2 s  .  c o m*/
}

From source file:org.hibernate.search.elasticsearch.util.impl.gson.ES2NormsTypeJsonAdapter.java

License:LGPL

@Override
public NormsType read(JsonReader in) throws IOException {
    // Ignore: we don't support norms on ES2
    in.skipValue();
    return null;//from w w w .  j av  a 2  s .c  o m
}

From source file:org.hillview.table.rows.GuessSchema.java

License:Open Source License

/**
 * Throws if the value is not valid JSON
 * The gson parser is not strict enough: it parses
 * unquoted strings as JSON.String, so we have to do this manually.
 * Returns true if this is a complex json value, false otherwise.
 *//*from w  ww  .java 2s . c om*/
private static boolean isJsonValid(final JsonReader jsonReader) throws IOException {
    JsonToken token;
    boolean isComplex = false;
    loop: while ((token = jsonReader.peek()) != JsonToken.END_DOCUMENT && token != null) {
        switch (token) {
        case BEGIN_ARRAY:
            isComplex = true;
            jsonReader.beginArray();
            break;
        case END_ARRAY:
            isComplex = true;
            jsonReader.endArray();
            break;
        case BEGIN_OBJECT:
            isComplex = true;
            jsonReader.beginObject();
            break;
        case END_OBJECT:
            isComplex = true;
            jsonReader.endObject();
            break;
        case NAME:
            jsonReader.nextName();
            break;
        case STRING:
        case NUMBER:
        case BOOLEAN:
        case NULL:
            jsonReader.skipValue();
            break;
        case END_DOCUMENT:
            break loop;
        default:
            throw new AssertionError(token);
        }
    }
    return isComplex;
}

From source file:org.jboss.tools.aerogear.hybrid.core.plugin.registry.CordovaPluginRegistryManager.java

License:Open Source License

private void readPluginInfo(JsonReader reader, CordovaRegistryPluginInfo plugin) throws IOException {
    Assert.isNotNull(plugin);//from w  ww .  j av a  2  s.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) && plugin instanceof CordovaRegistryPlugin) {
                parseDetailedVersions(reader, (CordovaRegistryPlugin) plugin);
                break;
            }
            if ("dist".equals(name) && plugin instanceof CordovaRegistryPluginVersion) {
                parseDistDetails(reader, (CordovaRegistryPluginVersion) plugin);
                break;
            }
            if ("license".equals(name) && plugin instanceof CordovaRegistryPluginVersion) {
                CordovaRegistryPluginVersion v = (CordovaRegistryPluginVersion) plugin;
                v.setLicense(reader.nextString());
                break;
            }
            break;
        }

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