@Nullable
  private <T> T getOptionalField(
      boolean shouldUseNestedValue, JSONObject s, final String fieldId, JsonParser<T> jsonParser)
      throws JSONException {
    final JSONObject fieldJson = JsonParseUtil.getNestedOptionalObject(s, FIELDS, fieldId);
    // for fields like assignee (when unassigned) value attribute may be missing completely
    if (fieldJson != null) {
      if (shouldUseNestedValue) {
        final JSONObject valueJsonObject = fieldJson.optJSONObject(VALUE_ATTR);
        if (valueJsonObject != null) {
          return jsonParser.parse(valueJsonObject);
        }

      } else {
        return jsonParser.parse(fieldJson);
      }
    }
    return null;
  }
Пример #2
0
 /** The loop that will intercept and handle the incoming messages for Sytac */
 public void run() {
   try {
     while (!_hosebirdClient.isDone()) {
       String msg = _inMessages.take();
       ParsedJson parsed = _parser.parse(msg);
       _outMessages.add(parsed);
     }
     _hosebirdClient.stop();
   } catch (Exception e) {
     LOGGER.error(e.getMessage(), e);
   }
 }
  private ArrayList<RemoteObject> deserializeArrayAsJson(String queryScope, String input) {
    ArrayList<RemoteObject> objects = new ArrayList<RemoteObject>();

    JsonParser parser = new JsonParser(input);
    JsonArray parent =
        ((JsonElement)
                parser.parse(
                    HttpAdapter.createResponseWrangling(queryScope, this).getCollectionSelector(),
                    JsonElement.class))
            .getAsJsonArray();
    for (int i = 0; i < parent.size(); i++) {
      objects.add(deserialize(queryScope, new JsonParser(parent.get(i))));
    }

    return objects;
  }
 private void build(StringBuilder sb, Map<String, Object> map) {
   boolean started = false;
   for (Map.Entry<String, Object> me : map.entrySet()) {
     if (started) {
       sb.append(',');
     }
     // try to parse message as JSON
     if ("message".equals(me.getKey()) && me.getValue() != null) {
       JsonParser parser = new JsonParser(new StringReader(me.getValue().toString()));
       try {
         build(sb, (Map<String, Object>) parser.parse());
       } catch (Throwable e) {
         sb.append("\"").append(me.getKey()).append("\":");
         build(sb, me.getValue());
       }
     } else {
       sb.append("\"").append(me.getKey()).append("\":");
       build(sb, me.getValue());
     }
     started = true;
   }
 }
 @Override
 public T parse(Object o) throws JSONException {
   return jsonParser.parse(convert(o, JSONObject.class));
 }