Package net.minidev.json

Examples of net.minidev.json.JSONArray


      for (final String field : dlsPermission.keySet()) {

        final DlsPermission dlsPerm = new DlsPermission();
        dlsPerm.setField(field);

        JSONArray ja = (JSONArray) ((JSONObject) dlsPermission
            .get(field)).get("read");
        dlsPerm.addReadTokens(ja.toArray(new String[0]));

        ja = (JSONArray) ((JSONObject) dlsPermission.get(field))
            .get("update");
        dlsPerm.addUpdateTokens(ja.toArray(new String[0]));

        ja = (JSONArray) ((JSONObject) dlsPermission.get(field))
            .get("delete");
        dlsPerm.addDeleteTokens(ja.toArray(new String[0]));

        perms.add(dlsPerm);
      }

    }
View Full Code Here


            }//TESTED (by hand)
            if (key.startsWith(":")) { // jpath
              key = "$" + key;
            }
            // NOTE: *not* org.json.JSONArray
            JSONArray candidateEntities = null;
            if (key.startsWith("$")) {
              JSONArray candidateEntities_tmp = JsonPath.read(json.toString(), key.replace(':', '.'));
              if (null != candidateEntities_tmp) {
                candidateEntities = new JSONArray();
                for (Object o: candidateEntities_tmp) {
                  if (o instanceof String) {
                    candidateEntities.add(o);
                  }
                  else if (o instanceof JSONArray) {
                    candidateEntities.addAll((JSONArray)o);
                  }
                }//TESTED (displayUrl vs entities, 3.2)
              }             
              //DEBUG
              //System.out.println(candidateEntities);
             
            }//(TESTED (permutations above by hand))
            else {
              String s = (String) MongoDbUtil.getProperty(json, key.replace(':', '.'));
              if (null != s) {
                candidateEntities = new JSONArray();
                candidateEntities.add(s);
              }
            }//TESTED (3.1)                     
           
            if (null != candidateEntities) for (int i = 0; i < candidateEntities.size(); ++i) {
View Full Code Here

    MockHttpServletResponse response = request(byFirstNameLink.expand("Daenerys"),
        MediaType.parseMediaType("application/x-spring-data-compact+json"));

    String responseBody = response.getContentAsString();

    JSONArray personLinks = JsonPath.<JSONArray> read(responseBody, "$.links[?(@.rel=='person')].href");

    assertThat(personLinks, hasSize(1));
    assertThat(personLinks.get(0), is((Object) daenerysLink.getHref()));
    assertThat(JsonPath.<JSONArray> read(responseBody, "$.content"), hasSize(0));
  }
View Full Code Here

    assertThat(String.format("JSONPath lookup for %s did return null in %s.", path, content), jsonPathResult,
        is(notNullValue()));

    if (jsonPathResult instanceof JSONArray) {
      JSONArray array = (JSONArray) jsonPathResult;
      assertThat(array, hasSize(greaterThan(0)));
    }

    return (T) jsonPathResult;
  }
View Full Code Here

      for (String linkedRel : linked.getValue()) {

        // Find URIs pointing to linked resources
        String jsonPath = String.format("$..%s._links.%s.href", linked.getKey(), linkedRel);
        String representation = resource.getContentAsString();
        JSONArray uris = JsonPath.read(representation, jsonPath);

        for (Object href : uris) {

          follow(href.toString()). //
              andExpect(status().isOk());
View Full Code Here

    String response = template.getForObject(URI_TEMPLATE, String.class, MILESTONE_ID);

    JsonPath titlePath = JsonPath.compile("$[*].title");
    JsonPath idPath = JsonPath.compile("$[*].number");

    JSONArray titles = titlePath.read(response);
    Iterator<Object> ids = ((JSONArray) idPath.read(response)).iterator();

    System.out.println("Milestone - " + JsonPath.read(response, "$[1].milestone.title"));

    for (Object title : titles) {
View Full Code Here

  private List<Link> createLinksFrom(Object parseResult, String rel) {

    if (parseResult instanceof JSONArray) {

      List<Link> links = new ArrayList<Link>();
      JSONArray array = (JSONArray) parseResult;

      for (Object element : array) {
        links.add(new Link(element.toString(), rel));
      }
View Full Code Here

          if (object instanceof Map) {
            for (String key : object.keySet()) {

              if (key.equalsIgnoreCase("events")) {

                JSONArray evts = (JSONArray) object.get(key);
                AuditEventMessage[] msgs = new AuditEventMessage[evts
                    .size()];

                for (int i = 0; i < evts.size(); i++) {

                  IronBeeEventMessage ib = new IronBeeEventMessage();

                  log.debug("events[{}] = {}", i, evts.get(i));

                  JSONObject event = (JSONObject) evts.get(i);
                  log.debug("  message: {}", event);
                  for (String k : event.keySet()) {
                    log.debug("     message[{}] = {}", k,
                        event.get(k));

                    Object obj = event.get(k);
                    if (obj instanceof JSONArray) {
                      JSONArray arr = (JSONArray) obj;
                      String[] d = new String[arr.size()];
                      for (int idx = 0; idx < arr.size(); idx++) {
                        d[idx] = arr.get(idx)
                            .toString();
                      }
                      log.debug("Setting {} = {}", k, d);
                      ib.set(k, d);
                    } else {
View Full Code Here

            this.hitCache = true;
            return cache.get(path);
        }
        String[] params = path.split("\\.");
        JSONObject json = this.root;
        JSONArray jsonArray = null;
        String currentPath = "";
        for (int i = 0; i < params.length - 1; i++) {
            String param = params[i];
            if (cachePolicy.equals(CachePolicy.CACHE_ALL_LEVELS)) {
                if (!currentPath.isEmpty()) {
                    currentPath += ".";
                }
                currentPath += param;
            }
            if (param.startsWith("$")) {
                if (jsonArray == null) {
                    throw new JSONOperationErrorException("Not illegal syntax at this place: " + param);
                }
                int index = getIndex(param);
                json = (JSONObject) jsonArray.get(index);
                jsonArray = null;
            } else if (param.contains("[")) {
                int find = param.indexOf("[");
                String newParam = param.substring(0, find);
                String s = param.substring(find+1, param.indexOf("]"));
                if (s.isEmpty()) {
                    jsonArray = (JSONArray) json.get(newParam);
                    json = null;
                } else {
                    int index = Integer.parseInt(s);
                    json = (JSONObject)((JSONArray) json.get(newParam)).get(index);
                    jsonArray = null;
                }
            } else {
                Object obj = json.get(param);
                if (obj instanceof JSONObject) {
                    json = (JSONObject) obj;
                    jsonArray = null;
                } else if (obj instanceof JSONArray) {
                    jsonArray = (JSONArray) obj;
                    json = null;
                } else if (obj == null) {
                    throw new IllegalStateException("json object is null");
                } else {
                    throw new IllegalStateException("json object ('"+param+"') has wrong type: " + obj.getClass());
                }

            }
            if (cachePolicy.equals(CachePolicy.CACHE_ALL_LEVELS)) {
                saveToCache(currentPath, json);
            }
        }
        String name = params[params.length - 1];

        Object value;
        if (name.startsWith("$")) {
            if (jsonArray == null) {
                throw new JSONOperationErrorException("Not illegal syntax at this place: " + name);
            }
            int index = getIndex(name);
            value = jsonArray.get(index);
        } else {
            value = json.get(name);
        }

        saveToCache(path, value);
View Full Code Here

    return (this.generateObject (1.0f));
  }
 
  protected final JSONArray generateArray (final float chance)
  {
    final JSONArray array;
    if (this.random.nextFloat () <= chance) {
      array = new JSONArray ();
      while (true) {
        if (this.random.nextFloat () > chance)
          break;
        array.add (this.generateObject (chance * 0.9f));
      }
    } else
      array = null;
    return (array);
  }
View Full Code Here

TOP

Related Classes of net.minidev.json.JSONArray

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.