Example usage for com.google.gson JsonParser JsonParser

List of usage examples for com.google.gson JsonParser JsonParser

Introduction

In this page you can find the example usage for com.google.gson JsonParser JsonParser.

Prototype

@Deprecated
public JsonParser() 

Source Link

Usage

From source file:com.blackducksoftware.integration.hub.teamcity.server.global.ServerHubConfigPersistenceManager.java

License:Apache License

public ServerHubConfigPersistenceManager(@NotNull final ServerPaths serverPaths) {
    gson = new Gson();
    jsonParser = new JsonParser();
    configFile = new File(serverPaths.getConfigDir(), CONFIG_FILE_NAME);
    loadSettings();// w ww  .j a  v a2s .  c  o  m
}

From source file:com.bosch.osmi.bdp.access.mock.BdpApiAccessMockImpl.java

License:Open Source License

private JsonObject readJsonFile(Reader jsonReader) {
    // Read from File to String
    JsonParser parser = new JsonParser();
    JsonElement jsonElement = parser.parse(jsonReader);
    return jsonElement.getAsJsonObject();
}

From source file:com.brainardphotography.gravatar.contact.PCContactLoader.java

License:Apache License

private PCContactLoader() {
    gson = new Gson();
    jsonParser = new JsonParser();
}

From source file:com.braindrainpain.docker.DockerRepository.java

License:Open Source License

/**
 * Call the Docker API./*from w w  w  .  j a  v  a2  s .c o  m*/
 * 
 * @param packageConfiguration
 * @return 
 */
private JsonObject allTags(final PackageConfiguration packageConfiguration) {
    JsonObject result = null;
    HttpClient client = super.getHttpClient();

    String repository = MessageFormat.format(DockerAPI.V1.getUrl(),
            repositoryConfiguration.get(Constants.REGISTRY).getValue(),
            packageConfiguration.get(Constants.REPOSITORY).getValue());

    try {
        GetMethod get = new GetMethod(repository);
        if (client.executeMethod(get) == HttpStatus.SC_OK) {
            String jsonString = get.getResponseBodyAsString();
            LOG.info("RECIEVED: " + jsonString);
            result = (JsonObject) new JsonParser().parse(jsonString);
        }
    } catch (IOException e) {
        // Wrap into a runtime. There is nothing useful to do here
        // when this happens.
        throw new RuntimeException("Cannot fetch the tags from " + repository, e);
    }

    return result;
}

From source file:com.braindrainpain.docker.httpsupport.HttpClientService.java

License:Open Source License

private JsonArray parseJson(String jsonString, String memberName) {
    return (JsonArray) ((JsonObject) new JsonParser().parse(jsonString)).get(memberName);
}

From source file:com.broadlink.control.api.BroadlinkAPI.java

/**
 * Execute a Broadlink API with the given parameters
 *//*from ww  w .j  a  v a2s  . c om*/
private JsonObject broadlinkExecuteCommand(JsonObject params) {
    if (mBlNetwork == null) {
        Log.e(this.getClass().getSimpleName(), "mBlNetwork is uninitialized, check app permissions");
        return null;
    }
    String responseString = mBlNetwork.requestDispatch(params.toString());
    JsonObject responseJsonObject = new JsonParser().parse(responseString).getAsJsonObject();
    Log.d(this.getClass().getSimpleName(), responseString);
    return responseJsonObject;
}

From source file:com.buddycloud.channeldirectory.cli.Main.java

License:Apache License

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {

    JsonElement rootElement = new JsonParser().parse(new FileReader(QUERIES_FILE));
    JsonArray rootArray = rootElement.getAsJsonArray();

    Map<String, Query> queries = new HashMap<String, Query>();

    for (int i = 0; i < rootArray.size(); i++) {
        JsonObject queryElement = rootArray.get(i).getAsJsonObject();
        String queryName = queryElement.get("name").getAsString();
        String type = queryElement.get("type").getAsString();

        Query query = null;/*from  w ww. j ava 2  s  .  com*/

        if (type.equals("solr")) {
            query = new QueryToSolr(queryElement.get("agg").getAsString(),
                    queryElement.get("core").getAsString(), queryElement.get("q").getAsString());
        } else if (type.equals("dbms")) {
            query = new QueryToDBMS(queryElement.get("q").getAsString());
        }

        queries.put(queryName, query);
    }

    LinkedList<String> queriesNames = new LinkedList<String>(queries.keySet());
    Collections.sort(queriesNames);

    Options options = new Options();
    options.addOption(OptionBuilder.isRequired(true).withLongOpt("query").hasArg(true)
            .withDescription("The name of the query. Possible queries are: " + queriesNames).create('q'));

    options.addOption(OptionBuilder.isRequired(false).withLongOpt("args").hasArg(true)
            .withDescription("Arguments for the query").create('a'));

    options.addOption(new Option("?", "help", false, "Print this message"));

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        printHelpAndExit(options);
    }

    if (cmd.hasOption("help")) {
        printHelpAndExit(options);
    }

    String queryName = cmd.getOptionValue("q");
    String argsCmd = cmd.getOptionValue("a");

    Properties configuration = ConfigurationUtils.loadConfiguration();

    Query query = queries.get(queryName);
    if (query == null) {
        printHelpAndExit(options);
    }

    System.out.println(query.exec(argsCmd, configuration));

}

From source file:com.buddycloud.channeldirectory.crawler.node.ActivityHelper.java

License:Apache License

/**
 * @param channelJid//w ww .  j a  v a  2 s. c  om
 * @return
 * @throws SQLException 
 */
private static ChannelActivity retrieveActivityFromDB(String channelJid, ChannelDirectoryDataSource dataSource)
        throws SQLException {
    PreparedStatement statement = null;
    try {
        statement = dataSource.prepareStatement("SELECT * FROM channel_activity WHERE channel_jid = ?",
                channelJid);
        ResultSet resultSet = statement.executeQuery();
        if (resultSet.next()) {
            Date updated = new Date(resultSet.getTimestamp("updated").getTime());
            Date earliest = new Date(resultSet.getTimestamp("earliest").getTime());
            String detailedActivity = resultSet.getString("detailed_activity");
            JsonArray detailedActivityJson = new JsonParser().parse(detailedActivity).getAsJsonArray();
            return new ChannelActivity(detailedActivityJson, updated, earliest);
        }

        return null;

    } catch (SQLException e1) {
        LOGGER.error(e1);
        throw e1;
    } finally {
        ChannelDirectoryDataSource.close(statement);
    }
}

From source file:com.buddycloud.friendfinder.HttpUtils.java

License:Apache License

public static JsonElement consumeJSON(String URL) throws Exception {
    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(URL);
    HttpResponse httpResponse = client.execute(httpGet);

    JsonElement parse = new JsonParser()
            .parse(new JsonReader(new InputStreamReader(httpResponse.getEntity().getContent())));

    return parse;
}

From source file:com.ca.dvs.utilities.raml.JsonUtil.java

License:Open Source License

/**
 * Compare two JSON strings// ww w . ja v a  2s. co  m
 * @param json1 the first of two JSON objects to compare
 * @param json2 the second of two JSON objects to compare
 * @return true when the JSON strings compare favorably, otherwise false
 */
public static boolean equals(String json1, String json2) {

    boolean match = false;

    if (null != json1 && null != json2) {
        JsonParser parser = new JsonParser();

        Object obj1 = parser.parse(json1);
        Object obj2 = parser.parse(json2);

        if (obj1 instanceof JsonObject && obj2 instanceof JsonObject) {
            JsonObject jObj1 = (JsonObject) obj1;
            JsonObject jObj2 = (JsonObject) obj2;
            match = jObj1.equals(jObj2);
        } else if (obj1 instanceof JsonArray && obj2 instanceof JsonArray) {
            JsonArray jAry1 = (JsonArray) obj1;
            JsonArray jAry2 = (JsonArray) obj2;
            match = jAry1.equals(jAry2);
        }
    }
    return match;
}