Package com.google.gwt.json.client

Examples of com.google.gwt.json.client.JSONString


    exitCode = null; // Needs to become set.
    result = null; // not?
    for (int i = 0; i < keys.length; i++) {
      String key = (String) keys[i];
      JSONValue v = jso.get(key);
      JSONString valueObj = v.isString();
      if (valueObj == null) {
        GenClient.showDebug("Skipping key [" + key + "] with non-String value [" + v.toString() + "]");
        continue;
      }
      String value = valueObj.stringValue();
      endIndex = Math.min(value.length(), Settings.MAX_RESPONSE_REPORTED_FOR_DEBUGGING);
      String valueTruncate = value.substring(0,endIndex);
      GenClient.showDebug("Received key, valueTruncate: [" + key + "], [" + valueTruncate + "]");
      if (key.equals(Settings.FORM_PARM_ACTION)) {
        action = value;
View Full Code Here


        return getDocument(JSONParser.parseStrict(string).isObject());
    }

    public JSONObject toJson(Item item) {
        JSONObject result = new JSONObject();
        result.put(KEY, new JSONString(toNullableValue(item.getKey())));
        result.put(ID, new JSONNumber(item.getId()));
        result.put(TEXT, new JSONString(item.getText()));
        result.put(PRIORITY, new JSONString(item.getPriority().toString()));
        result.put(STATUS, new JSONString(item.getStatus().toString()));
        result.put(CREATED, new JSONNumber(item.getCreated().getTime()));
        result.put(UPDATED, new JSONNumber(item.getUpdated().getTime()));
        return result;
    }
View Full Code Here

        return new Item(key, id, text, priority, status, created, updated);
    }

    public JSONObject toJson(Document document) {
        JSONObject result = new JSONObject();
        result.put(USER_ID, new JSONString(document.getUserId()));
        result.put(LAST_SAVED,
            new JSONNumber(document.getLastSaved().getTime()));
        return result;
    }
View Full Code Here

  protected static JSONObject encodeMap(Map<String, Object> data) {
    JSONObject jsobj = new JSONObject();
    for (String key : data.keySet()) {
      Object val = data.get(key);
      if (val instanceof String) {
        jsobj.put(key, new JSONString(encodeValue(val)));
      } else if (val instanceof Date) {
        jsobj.put(key, new JSONString(encodeValue(val)));
      } else if (val instanceof Number) {
        jsobj.put(key, new JSONString(encodeValue(val)));
      } else if (val instanceof Boolean) {
        jsobj.put(key, JSONBoolean.getInstance((Boolean) val));
      } else if (val == null) {
        jsobj.put(key, JSONNull.getInstance());
      } else if (val instanceof Map) {
View Full Code Here

      } else if (val instanceof Map) {
        jsona.set(i, encodeMap((Map<String, Object>) val));
      } else if (val instanceof List) {
        jsona.set(i, encodeList((List<Object>) val));
      } else if (val instanceof String) {
        jsona.set(i, new JSONString(encodeValue(val)));
      } else if (val instanceof Number) {
        jsona.set(i, new JSONString(encodeValue(val)));
      } else if (val instanceof Boolean) {
        jsona.set(i, JSONBoolean.getInstance((Boolean) val));
      } else if (val == null) {
        jsona.set(i, JSONNull.getInstance());
      } else if (val instanceof Date) {
        jsona.set(i, new JSONString(encodeValue(val)));
      }
    }
    return jsona;
  }
View Full Code Here

     * @param callback the REST callback to indicate the call is completed
     */
    public void logout(final RESTObjectCallBack<String> callback)
    {
        JSONObject credentials = new JSONObject();
        credentials.put(USER_TOKEN, new JSONString(RESTility.getUserToken()));
        credentials.put(AUTH_URL_TOKEN, new JSONString(RESTility.getTokenServerUrl()));
        credentials.put(AUTH_LOGOUT_URL_TOKEN, new JSONString(RESTility.getTokenServerLogoutUrl()));

        RESTility.callREST(getServletContext() + "/auth", credentials.toString(), RESTility.DELETE,
                           new RESTCallback() {
                @Override
                public void onSuccess(JSONValue val)
View Full Code Here

     */
    public void login(final String username, final String password, final String authUrl,
                             final RESTObjectCallBack<String> callback)
    {
        JSONObject credentials = new JSONObject();
        credentials.put(USERNAME_TOKEN, new JSONString(username));
        credentials.put(PASSWORD_TOKEN, new JSONString(password));
        credentials.put(AUTH_URL_TOKEN, new JSONString(authUrl));
        if (RESTility.getTokenServerLogoutUrl() != null) {
            credentials.put(AUTH_LOGOUT_URL_TOKEN, new JSONString(RESTility.getTokenServerLogoutUrl()));
        } else {
            credentials.put(AUTH_LOGOUT_URL_TOKEN, new JSONString(authUrl));
        }

        RESTility.callREST(getServletContext() + "/auth", credentials.toString(), RESTility.POST,
                           new RESTCallback() {
                @Override
View Full Code Here

        expect(16);
       
        String testString = "Test String";
       
        JSONObject obj = new JSONObject();
        obj.put("stringVal", new JSONString(testString));
        obj.put("intVal", new JSONNumber(99));
        obj.put("intStringVal", new JSONString("99"));
        obj.put("booleanVal", JSONBoolean.getInstance(true));
        obj.put("booleanStringVal", new JSONString("true"));
        obj.put("dateStringVal", new JSONString("1293373801745"));
       
        /*
         String tests
         */
        ok(testString.equals(JSONUtil.getStringValue(obj, "stringVal")),
View Full Code Here

        JSONObject fault = new JSONObject();
        obj.put("Fault", fault);
       
        JSONObject code = new JSONObject();
        fault.put("Code", code);
        code.put("Value", new JSONString("Sender"));
       
        JSONObject subcode = new JSONObject();
        code.put("Subcode", subcode);
        subcode.put("Value", new JSONString("MessageSubcodeTest"));
       
        JSONObject reason = new JSONObject();
        fault.put("Reason", reason);
        reason.put("Text", new JSONString("Test Reason"));
       
        JSONObject detail = new JSONObject();
        fault.put("Detail", detail);
        detail.put("Value1", new JSONString("First Value"));
        detail.put("Value2", new JSONString("Second Value"));
       
        RESTException exception = JSONUtil.getRESTException(obj, -1, "url");
       
        ok(null != exception, "Getting RESTException should be a value object.  It was " + exception);

        ok("Sender".equals(exception.getCode()), "Getting RESTException code should be Sender.  It was " + exception.getCode());

        ok("MessageSubcodeTest".equals(exception.getSubcode()),
           "Getting RESTException subcode should be MessageSubcodeTest.  It was " + exception.getSubcode());

        ok("Test Reason".equals(exception.getReason()),
           "Getting RESTException reason should be Test Reason.  It was " + exception.getReason());
       
        ok("First Value".equals(exception.getDetails().get("Value1")),
           "Getting RESTException details first value should be First Value.  It was " + exception.getDetails().get("Value1"));
       
        ok("Second Value".equals(exception.getDetails().get("Value2")),
           "Getting RESTException details first value should be Second Value.  It was " + exception.getDetails().get("Value2"));
       
        /*
         Now we'll test a value that isn't an NCAC fault
         */
        obj = new JSONObject();
        obj.put("foo", new JSONString("foo"));
        obj.put("bar", new JSONString("bar"));
       
        ok(null == JSONUtil.getRESTException(obj, -1, "url"),
           "Getting RESTException for JSON data that doesn't represent an NCAC exception should be null.  It was " +
           JSONUtil.getRESTException(obj, -1, "url"));
    }
View Full Code Here

             */
            offset = 0;
        }
       
        JSONObject obj = new JSONObject();
        obj.put("dateStringVal", new JSONString("1293373801745"));
        Date d = JSONUtil.getDateValue(obj, "dateStringVal");
        d = JSDateUtil.dateAdd(d, offset, "HOUR");
       
        if (!"12/26/2010 9:30 AM".equals(JSDateUtil.getShortDateTime(d))) {
            /*
 
View Full Code Here

TOP

Related Classes of com.google.gwt.json.client.JSONString

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.