Package org.json

Examples of org.json.JSONObject.opt()


                return false;
            }
            Iterator<?> keys = jsonExpected.keys();
            while (keys.hasNext()) {
                String key = (String)keys.next();
                if (!isJSONEquals(jsonExpected.opt(key), jsonActual.opt(key))) {
                    return false;
                }
            }
            return true;
        }
View Full Code Here


            JSONArray jsonActual = (JSONArray)actual;
            if (jsonExpected.length() != jsonActual.length()) {
                return false;
            }
            for (int i = 0; i < jsonExpected.length(); ++i) {
                if (!isJSONEquals(jsonExpected.opt(i), jsonActual.opt(i))) {
                    return false;
                }
            }
            return true;
        }
View Full Code Here

    if (obj instanceof JSONObject) {
      JSONObject json = (JSONObject) obj;

      // Does this object have a "list" property that is an array?
      // TODO: add to specification
      Object childList = json.opt("list");
      if (childList instanceof JSONArray) {
        return coerceToIterable(childList);
      }

      // A scalar JSON value is treated as a single element list.
View Full Code Here

    JSONObject clone = new JSONObject(base, JSONObject.getNames(base));
    // Walk parameter list for the merged object and merge recursively.
    String[] fields = JSONObject.getNames(merge);
    for (String field : fields) {
      Object existing = clone.opt(field);
      Object update = merge.get(field);
      if (existing == null || update == null) {
        // It's new custom config, not referenced in the prototype, or
        // it's removing a pre-configured value.
        clone.put(field, update);
View Full Code Here

    JSONObject clone = new JSONObject(base, JSONObject.getNames(base));
    // Walk parameter list for the merged object and merge recursively.
    String[] fields = JSONObject.getNames(merge);
    for (String field : fields) {
      Object existing = clone.opt(field);
      Object update = merge.get(field);
      if (JSONObject.NULL.equals(existing) || JSONObject.NULL.equals(update)) {
        // It's new custom config, not referenced in the prototype, or
        // it's removing a pre-configured value.
        clone.put(field, update);
View Full Code Here

    if (obj instanceof JSONObject) {
      JSONObject json = (JSONObject) obj;
     
      // Does this object have a "list" property that is an array?
      // TODO: add to specification
      Object childList = json.opt("list");
      if (childList instanceof JSONArray) {
        return coerceToIterable(childList);
      }
     
      // A scalar JSON value is treated as a single element list.
View Full Code Here

  static private void applyStringAttributePatch(Object obj, String objKey, JSONObject patch, String patchKey) throws Exception {
    Object patchValue = patch.get(patchKey);

    if( obj instanceof JSONObject ){
      JSONObject jsonObj = (JSONObject)obj;
      Object currentValue = jsonObj.opt(objKey);
      if( null == currentValue ){
        // Clone
        if( patchValue instanceof JSONObject ) {
          JSONObject clone = JSONSupport.copyObject((JSONObject)patchValue);
          jsonObj.put(objKey, clone);
View Full Code Here

        Assert.assertEquals("string", json.optString("string"));
        Assert.assertEquals(123, json.optInt("int"));
        Assert.assertEquals(123.456, json.optDouble("double"), 1e-15);
        Assert.assertEquals(true, json.optBoolean("true"));
        Assert.assertEquals(false, json.optBoolean("false"));
        Assert.assertEquals(null, json.opt("null"));
    }

    @Test
    public void testArray() {
        JSONArray json = OTJson.array("string", 123, 123.456, true, false, null);
View Full Code Here

        try {
            if (user != null) {
                JSONObject userJson = OTUser.SERIALIZER.toJson(user);
                for (Iterator it = userJson.keys(); it.hasNext(); ) {
                    String key = (String) it.next();
                    json.put(key, userJson.opt(key));
                }
            }
            json.put("signinNow", signinNow);
        } catch (JSONException e) {
            throw new OTException(e);
View Full Code Here

   private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
      try {
         JSONObject payload = new JSONObject(frame.getTextData());
         String opCode = (String) payload.get(OpHandler.OP_CODE);
         String cacheName = (String) payload.opt(OpHandler.CACHE_NAME);
         Cache<Object, Object> cache = getCache(cacheName);

         OpHandler handler = operationHandlers.get(opCode);
         if (handler != null) {
            handler.handleOp(payload, cache, ctx);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.