Package net.minidev.json

Examples of net.minidev.json.JSONObject


public class SimpleResponseRepresenter implements Representer<SimpleResponse> {

    public JSONObject toJSON(Resource<SimpleResponse> resource) {
        SimpleResponse response = resource.getDefault();

        JSONObject json = new JSONObject();
        json.put("code", response.getCode());
        json.put("message", response.getMessage());

        return json;
    }
View Full Code Here


          log.debug("Handling JSON content, parts is named {}");
          JSONParser p = new JSONParser(
              JSONParser.DEFAULT_PERMISSIVE_MODE);

          JSONObject object = p.parse(reader, JSONObject.class);
          log.debug("object: {}", object);

          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 {
                      ib.set(k, event.get(k).toString());
                    }
                  }
                  msgs[i] = ib;
                }
View Full Code Here

        if (cache.containsKey(path)) {
            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);

        return value;
View Full Code Here

    return (array);
  }
 
  protected final JSONObject generateObject (final float chance)
  {
    final JSONObject object;
    if (this.random.nextFloat () <= chance) {
      object = new JSONObject ();
      object.put ("some-boolean", Boolean.valueOf (this.random.nextBoolean ()));
      object.put ("some-integer", Long.valueOf (this.random.nextLong ()));
      object.put ("some-float", Float.valueOf (this.random.nextFloat ()));
      object.put ("some-string", Long.toString (this.random.nextLong ()));
      object.put ("some-object", this.generateObject (chance * 0.9f));
      object.put ("some-array", this.generateArray (chance * 0.9f));
    } else
      object = null;
    return (object);
  }
View Full Code Here

  {
    Preconditions.checkNotNull (message);
    Preconditions.checkArgument (message.type != null, "unexpected message-type value: `%s`", message.type);
    Preconditions.checkArgument ((message.metaData != null), "unexpected meta-data value: `%s`", message.metaData);
    Preconditions.checkNotNull (message.data);
    final JSONObject metaDataValue = new JSONObject (message.metaData);
    metaDataValue.put ("__type__", message.type.identifier);
    final ByteBuffer metaData = this.jsonCoder.encode (metaDataValue);
    final ByteBuffer data = message.data.asReadOnlyBuffer ();
    final int packetSize = metaData.remaining () + 1 + data.remaining ();
    final ByteBuffer packet = ByteBuffer.allocate (packetSize + 4);
    packet.putInt (packetSize);
View Full Code Here

   */
  public JSONObject toJSONObject() {

    // Include custom parameters, they will be overwritten if their
    // names match specified registered ones
    JSONObject o = new JSONObject(customParams);

    // Alg is always defined
    o.put("alg", alg.toString());

    if (typ != null) {
      o.put("typ", typ.toString());
    }

    if (cty != null) {
      o.put("cty", cty);
    }

    if (crit != null && ! crit.isEmpty()) {
      o.put("crit", new ArrayList<>(crit));
    }

    return o;
  }
View Full Code Here

   */
  public static Header parse(final String jsonString,
           final Base64URL parsedBase64URL)
    throws ParseException {

    JSONObject jsonObject = JSONObjectUtils.parseJSONObject(jsonString);

    return parse(jsonObject, parsedBase64URL);
  }
View Full Code Here


  @Override
  public JSONObject toJSONObject() {

    JSONObject o = super.toJSONObject();

    if (enc != null) {
      o.put("enc", enc.toString());
    }

    if (epk != null) {
      o.put("epk", epk.toJSONObject());
    }

    if (zip != null) {
      o.put("zip", zip.toString());
    }

    if (apu != null) {
      o.put("apu", apu.toString());
    }
   
    if (apv != null) {
      o.put("apv", apv.toString());
    }

    if (p2s != null) {
      o.put("p2s", p2s.toString());
    }

    if (p2c > 0) {
      o.put("p2c", p2c);
    }

    if (iv != null) {
      o.put("iv", iv.toString());
    }

    if (tag != null) {
      o.put("tag", tag.toString());
    }

    return o;
  }
View Full Code Here

    keyList.add(oct2);

    JWKSet privateSet = new JWKSet(keyList);

    final boolean publicParamsOnly = true;
    JSONObject jsonObject = privateSet.toJSONObject(publicParamsOnly);

    JWKSet publicSet = JWKSet.parse(jsonObject.toJSONString());

    assertEquals(0, publicSet.getKeys().size());
  }
View Full Code Here


  @Override
  public JSONObject toJSONObject() {

    JSONObject o = super.toJSONObject();

    if (jku != null) {
      o.put("jku", jku.toString());
    }

    if (jwk != null) {
      o.put("jwk", jwk.toJSONObject());
    }

    if (x5u != null) {
      o.put("x5u", x5u.toString());
    }

    if (x5t != null) {
      o.put("x5t", x5t.toString());
    }

    if (x5t256 != null) {
      o.put("x5t#S256", x5t256.toString());
    }

    if (x5c != null && ! x5c.isEmpty()) {
      o.put("x5c", x5c);
    }

    if (kid != null) {
      o.put("kid", kid);
    }

    return o;
  }
View Full Code Here

TOP

Related Classes of net.minidev.json.JSONObject

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.