Package com.google.gwt.json.client

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


  }

  private static void unwrap(List<MarshalledMessage> messages, JSONArray val) {
    for (int i = 0; i < val.size(); i++) {
      JSONValue v = val.get(i);
      if (v.isArray() != null) {
        unwrap(messages, v.isArray());
      }
      else {
        messages.add(new MarshalledMessageImpl((JSONObject) v));
      }
    }
View Full Code Here


      for (int j = 0; j < modelType.getFieldCount(); j++) {
        DataField field = modelType.getField(j);
        String name = field.getName();
        Class type = field.getType();
        String map = field.getMap() != null ? field.getMap() : field.getName();
        JSONValue value = obj.get(map);

        if (value == null) continue;
        if (value.isArray() != null) {
          // nothing
        } else if (value.isBoolean() != null) {
          model.set(name, value.isBoolean().booleanValue());
        } else if (value.isNumber() != null) {
          if (type != null) {
            Double d = value.isNumber().doubleValue();
            if (type.equals(Integer.class)) {
              model.set(name, d.intValue());
            } else if (type.equals(Long.class)) {
              model.set(name, d.longValue());
            } else if (type.equals(Float.class)) {
              model.set(name, d.floatValue());
            } else {
              model.set(name, d);
            }
          } else {
            model.set(name, value.isNumber().doubleValue());
          }
        } else if (value.isObject() != null) {
          // nothing
        } else if (value.isString() != null) {
          String s = value.isString().stringValue();
          if (type != null) {
            if (type.equals(Date.class)) {
              if ("timestamp".equals(field.getFormat())) {
                Date d = new Date(Long.parseLong(s) * 1000);
                model.set(name, d);
              } else {
                DateTimeFormat format = DateTimeFormat.getFormat(field.getFormat());
                Date d = format.parse(s);
                model.set(name, d);
              }
            }
          } else {
            model.set(name, s);
          }
        } else if (value.isNull() != null) {
          model.set(name, null);
        }
      }
      models.add(model);
    }
View Full Code Here

    return (D) records;
  }

  protected int getTotalCount(JSONObject root) {
    if (modelType.getTotalName() != null) {
      JSONValue v = root.get(modelType.getTotalName());
      if (v != null) {
        if (v.isNumber() != null) {
          return (int) v.isNumber().doubleValue();
        } else if (v.isString() != null) {
          return Integer.parseInt(v.isString().stringValue());
        }
      }
    }
    return -1;
  }
View Full Code Here

    Bluetooth.listDevices(new StringCallback() {
      @Override
      public void onSuccess(String result) {
        try {
          String textHTML = "";
          JSONValue value = JSONParser.parseLenient(result);
          JSONArray devicesArray = value.isArray();

          if (devicesArray != null) {

            textHTML = "Result:";
View Full Code Here

    Bluetooth.listBoundDevices(new StringCallback() {
      @Override
      public void onSuccess(String result) {
        try {
          String textHTML = "";
          JSONValue value = JSONParser.parseLenient(result);
          JSONArray devicesArray = value.isArray();

          if (devicesArray != null) {
            textHTML = "Result:";
            for (int i = 0; i < devicesArray.size(); i++) {
              JSONObject deviceObj = devicesArray.get(i).isObject();
View Full Code Here

public class GwtGadgetInfoParser implements GadgetInfoParser {

  @Override
  public List<GadgetInfo> parseGadgetInfoJson(String json) {
    List<GadgetInfo> gadgetList = new ArrayList<GadgetInfo>();
    JSONValue value = JSONParser.parseStrict(json);
    JSONArray array = value.isArray();
    if (array != null) {
      for (int i = 0; i < array.size(); i++) {
        JSONValue item = array.get(i);
        GadgetInfo info = parseGadgetInfo(item);
        if (info != null) {
          gadgetList.add(info);
        }
      }
View Full Code Here

    if (prefs != null) {
      for (String pref : prefs.keySet()) {
        if (!has(pref)) {
          JSONObject prefJson = prefs.get(pref).isObject();
          if (prefJson != null) {
            JSONValue value = prefJson.get("default");
            if ((value != null) && (value.isString() != null)) {
              put(pref, value.isString().stringValue());
              log("Gadget pref '" + pref + "' = '" + get(pref) + "'");
            }
          } else {
            log("Invalid pref '" + pref + "' value in Gadget metadata.");
          }
View Full Code Here

   * @param key key of the value to extract.
   * @return the string object extracted from JSON (can be null if the value
   *         does not exist or is invalid.
   */
  private static String getJsonStringValue(JSONObject json, String key) {
    JSONValue value = json.get(key);
    JSONString string = (value == null) ? null : value.isString();
    if (string != null) {
      return string.stringValue();
    } else {
      return null;
    }
View Full Code Here

   * @param key key of the value to extract.
   * @return the Long object extracted from JSON (can be null if the value does
   *         not exist or is invalid.
   */
  private static Long getJsonLongValue(JSONObject json, String key) {
    JSONValue value = json.get(key);
    JSONNumber number = (value == null) ? null : value.isNumber();
    if (number != null) {
      return Math.round(number.doubleValue());
    } else {
      return null;
    }
View Full Code Here

   * @param key key of the value to extract.
   * @return the Boolean object extracted from JSON (can be null if the value
   *         does not exist or is invalid.
   */
  private static Boolean getJsonBooleanValue(JSONObject json, String key) {
    JSONValue value = json.get(key);
    JSONBoolean bool = (value == null) ? null : value.isBoolean();
    if (bool != null) {
      return bool.booleanValue();
    } else {
      return null;
    }
View Full Code Here

TOP

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

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.