Package org.json.simple.parser

Examples of org.json.simple.parser.JSONParser


  private Map<String, Response> getResponseMap0p8(String json,
      Map<String, Class<? extends Model>> modelClasses) {
    Map<String, Response> responses = new HashMap<String, Response>();

    JSONParser parser = new JSONParser();
    ContainerFactory containerFactory = getContainerFactory(Model.class);

    try {
      List<Map> rootArray = (List<Map>) parser.parse(json, containerFactory);

      for (Map responseObject : rootArray) {
        String id = null;
        Class<? extends Model> modelClass = null;
        Response response = new Response();
View Full Code Here


  private Response getResponseObject0p9(String json,
      final Class<? extends Model> modelClass) {
    Response response = new Response();

    JSONParser parser = new JSONParser();
    ContainerFactory containerFactory = getContainerFactory(modelClass);

    if (json.startsWith("{")) {
      try {
        Map rootObject = (Map) parser.parse(json, containerFactory);

        if (rootObject.containsKey("startIndex")) {
          response.setStartIndex(rootObject.get("startIndex"));
        }
        if (rootObject.containsKey("totalResults")) {
          response.setTotalResults(rootObject.get("totalResults"));
        }
        if (rootObject.containsKey("itemsPerPage")) {
          response.setItemsPerPage(rootObject.get("itemsPerPage"));
        }
        if (rootObject.containsKey("statusLink")) {
          response.setStatusLink(rootObject.get("statusLink"));
        }
        if (rootObject.containsKey("isFiltered")) {
          response.setIsFiltered(rootObject.get("isFiltered"));
        }
        if (rootObject.containsKey("person")) {
          response.getEntries().add((Model) rootObject.get("person"));
        } else if (rootObject.containsKey("entry")) {
          Object entry = rootObject.get("entry");
          if (entry.getClass().equals(JSONArray.class)) {
            for (int i = 0; i < ((List) entry).size(); i++) {
              Map currentEntry = (Map) ((List) entry).get(i);
              if (currentEntry.containsKey("person")) {
                response.getEntries().add((Model) currentEntry.get("person"));
              } else if (currentEntry.containsKey("activity")) {
                response.getEntries().add(
                    (Model) currentEntry.get("activity"));
              } else if (currentEntry.containsKey("album")) {
                response.getEntries().add((Model) currentEntry.get("album"));
              } else if (currentEntry.containsKey("mediaItem")) {
                response.getEntries().add(
                    (Model) currentEntry.get("mediaItem"));
              }
              else {
                response.getEntries().add((Model) currentEntry);
              }
            }
          }
        } else if (rootObject.containsKey("album")) {
          response.getEntries().add((Model) rootObject.get("album"));
        } else if (rootObject.containsKey("mediaItem")) {
          response.getEntries().add((Model) rootObject.get("mediaItem"));
        } else {
          response.getEntries().add((Model) rootObject);
        }
      } catch (ParseException e) {
        return null;
      }
    } else if (json.startsWith("[")) {
      try {
        List<Map> rootArray = (List<Map>) parser.parse(json, containerFactory);
        for (Map responseObject : rootArray) {
          response.getEntries().add((Model) responseObject);
        }
      } catch (ParseException e) {
        return null;
View Full Code Here

   *             string.
   */
  public static CassandraConfiguration create(String configuration)
      throws IOException, ParseException {
    final CassandraConfiguration result = new CassandraConfiguration();
    final JSONParser parser = new JSONParser();

    try {
      _log.info("Started checking whether configuration is a URI...");
      final File file = new File(configuration);
      if (file.exists()) {
        _log.info("Configuration is a file.");
        result.configure((JSONObject) parser
            .parse(new FileReader(file)));
        return result;
      } else {
        _log.info("Configuration is not a file.");
      }

      _log.info("Started checking whether configuration is a resource...");
      InputStream stream = null;
      try {
        stream = CassandraConfiguration.class
            .getResourceAsStream(configuration);
        _log.info("Configuration is a resource.");
      } catch (Exception e) {
        _log.info("Configuration is not a resource.");
      } finally {
        if (stream != null) {
          result.configure((JSONObject) parser
              .parse(new BufferedReader(new InputStreamReader(
                  stream))));
          return result;
        }
      }

      _log.info("Started checking whether configuration is a JSON string...");
      JSONObject configObject = null;
      try {
        configObject = (JSONObject) parser.parse(configuration);
      } catch (Exception e) {
        _log.info("Configuration is not a JSON string.");
      } finally {
        if (configObject != null) {
          _log.info("Configuration is a JSON string.");
View Full Code Here

    @Override
    public Jenkins createWorkspace(String jsonData, String serverUrl) {
        checkJsonDataAndThrowExceptionIfNecessary(jsonData);

        JSONParser parser = new JSONParser();
        Jenkins jenkins = new Jenkins("", serverUrl);

        try {
            JSONObject jsonObject = (JSONObject) parser.parse(jsonData);
            JSONObject primaryViewObject = (JSONObject) jsonObject.get(PRIMARY_VIEW);
            if (primaryViewObject != null) {
                jenkins.setPrimaryView(getView(primaryViewObject));
            }
View Full Code Here

    @Override
    public Job createJob(String jsonData) {
        checkJsonDataAndThrowExceptionIfNecessary(jsonData);

        JSONParser parser = new JSONParser();
        try {
            JSONObject jsonObject = (JSONObject) parser.parse(jsonData);

            return getJob(jsonObject);

        } catch (ParseException e) {
            String message = String.format("Error during parsing JSON data : %s", jsonData);
View Full Code Here

    }

    public Build createBuild(String jsonData) {
        checkJsonDataAndThrowExceptionIfNecessary(jsonData);

        JSONParser parser = new JSONParser();
        try {
            JSONObject jsonObject = (JSONObject) parser.parse(jsonData);

            return getBuild(jsonObject);

        } catch (ParseException e) {
            String message = String.format("Error during parsing JSON data : %s", jsonData);
View Full Code Here

    @Override
    public List<Job> createViewJobs(String jsonData) {
        checkJsonDataAndThrowExceptionIfNecessary(jsonData);

        JSONParser parser = new JSONParser();

        try {
            List<Job> jobs = new LinkedList<Job>();
            JSONObject jsonObject = (JSONObject) parser.parse(jsonData);
            JSONArray jobObjects = (JSONArray) jsonObject.get(JOBS);
            for (Object object : jobObjects) {
                JSONObject jobObject = (JSONObject) object;
                jobs.add(getJob(jobObject));
            }
View Full Code Here

    @Override
    public List<Job> createCloudbeesViewJobs(String jsonData) {
        checkJsonDataAndThrowExceptionIfNecessary(jsonData);

        JSONParser parser = new JSONParser();

        try {
            List<Job> jobs = new LinkedList<Job>();
            JSONObject jsonObject = (JSONObject) parser.parse(jsonData);
            JSONArray viewObjs = (JSONArray) jsonObject.get(VIEWS);
            if (viewObjs == null && viewObjs.isEmpty()) {
                return jobs;
            }
View Full Code Here

   *             string.
   */
  public static CassandraConfiguration create(String configuration)
      throws IOException, ParseException {
    final CassandraConfiguration result = new CassandraConfiguration();
    final JSONParser parser = new JSONParser();

    try {
      _log.info("Started checking whether configuration is a URI...");
      final File file = new File(configuration);
      if (file.exists()) {
        _log.info("Configuration is a file.");
        result.configure((JSONObject) parser
            .parse(new FileReader(file)));
        return result;
      } else {
        _log.info("Configuration is not a file.");
      }

      _log.info("Started checking whether configuration is a resource...");
      InputStream stream = null;
      try {
        stream = CassandraConfiguration.class
            .getResourceAsStream(configuration);
        _log.info("Configuration is a resource.");
      } catch (Exception e) {
        _log.info("Configuration is not a resource.");
      } finally {
        if (stream != null) {
          result.configure((JSONObject) parser
              .parse(new BufferedReader(new InputStreamReader(
                  stream))));
          return result;
        }
      }

      _log.info("Started checking whether configuration is a JSON string...");
      JSONObject configObject = null;
      try {
        configObject = (JSONObject) parser.parse(configuration);
      } catch (Exception e) {
        _log.info("Configuration is not a JSON string.");
      } finally {
        if (configObject != null) {
          _log.info("Configuration is a JSON string.");
View Full Code Here

     * @param json string to be parsed
     * @return a {@code JSONArray}
     * @throws {@code AssertionError} if the string cannot be parsed into a {@code JSONArray}
     */
    private JSONArray parseJSONArray(String json) throws AssertionError {
        JSONParser parser = new JSONParser();
        try {
            Object obj = parser.parse(json);
            assertTrue(obj instanceof JSONArray);
            return (JSONArray) obj;
        } catch (Exception e) {
            throw new AssertionError("not a valid JSON array: " + e.getMessage());
        }
View Full Code Here

TOP

Related Classes of org.json.simple.parser.JSONParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.