Пример #1
0
 public void writeJson(JsonWriter writer) throws IOException {
   if (messageParts.size() == 1) {
     latest().writeJson(writer);
   } else {
     writer.beginObject().name("text").value("").name("extra").beginArray();
     for (final MessagePart part : this) {
       part.writeJson(writer);
     }
     writer.endArray().endObject();
   }
 }
Пример #2
0
 public String toJSONString() {
   final JSONStringer json = new JSONStringer();
   try {
     if (messageParts.size() == 1) {
       latest().writeJson(json);
     } else {
       json.object().key("text").value("").key("extra").array();
       for (final MessagePart part : messageParts) {
         part.writeJson(json);
       }
       json.endArray().endObject();
     }
   } catch (final JSONException e) {
     throw new RuntimeException("invalid message");
   }
   return json.toString();
 }
Пример #3
0
 public String toJSONString() {
   if (!dirty && jsonString != null) {
     return jsonString;
   }
   StringWriter string = new StringWriter();
   JsonWriter json = new JsonWriter(string);
   try {
     if (messageParts.size() == 1) {
       latest().writeJson(json);
     } else {
       json.beginObject().name("text").value("").name("extra").beginArray();
       for (final MessagePart part : messageParts) {
         part.writeJson(json);
       }
       json.endArray().endObject();
       json.close();
     }
   } catch (Exception e) {
     throw new RuntimeException("invalid message");
   }
   jsonString = string.toString();
   dirty = false;
   return jsonString;
 }