Search in sources :

Example 76 with JsonObject

use of com.google.gson.JsonObject in project bigbluebutton by bigbluebutton.

the class AbstractService method addHeaderToMessage.

public String addHeaderToMessage(String jsonMessage, String messageName) {
    JsonObject payload = JsonEncoderUtil.buildPayload(jsonMessage);
    JsonObject header = JsonEncoderUtil.addMessageHeader(messageName);
    return new Gson().toJson(JsonEncoderUtil.headerAndPayload(header, payload));
}
Also used : JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson)

Example 77 with JsonObject

use of com.google.gson.JsonObject in project bigbluebutton by bigbluebutton.

the class JsonEncoderUtil method addMessageHeader.

public static JsonObject addMessageHeader(String name) {
    JsonObject header = new JsonObject();
    header.add("name", new JsonPrimitive(name));
    return header;
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject)

Example 78 with JsonObject

use of com.google.gson.JsonObject in project bigbluebutton by bigbluebutton.

the class CaptionClientMessageSender method handleCaptionMessage.

public void handleCaptionMessage(String message) {
    JsonParser parser = new JsonParser();
    JsonObject obj = (JsonObject) parser.parse(message);
    if (obj.has("header") && obj.has("payload")) {
        JsonObject header = (JsonObject) obj.get("header");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            switch(messageName) {
                case SendCaptionHistoryReplyMessage.SEND_CAPTION_HISTORY_REPLY:
                    SendCaptionHistoryReplyMessage sch = SendCaptionHistoryReplyMessage.fromJson(message);
                    if (sch != null) {
                        processSendCaptionHistoryReplyMessage(sch);
                    }
                    break;
                case UpdateCaptionOwnerMessage.UPDATE_CAPTION_OWNER:
                    UpdateCaptionOwnerMessage uco = UpdateCaptionOwnerMessage.fromJson(message);
                    if (uco != null) {
                        processUpdateCaptionOwnerMessage(uco);
                    }
                    break;
                case EditCaptionHistoryMessage.EDIT_CAPTION_HISTORY:
                    EditCaptionHistoryMessage ech = EditCaptionHistoryMessage.fromJson(message);
                    if (ech != null) {
                        processEditCaptionHistoryMessage(ech);
                    }
                    break;
            }
        }
    }
}
Also used : UpdateCaptionOwnerMessage(org.bigbluebutton.common.messages.UpdateCaptionOwnerMessage) JsonObject(com.google.gson.JsonObject) SendCaptionHistoryReplyMessage(org.bigbluebutton.common.messages.SendCaptionHistoryReplyMessage) EditCaptionHistoryMessage(org.bigbluebutton.common.messages.EditCaptionHistoryMessage) JsonParser(com.google.gson.JsonParser)

Example 79 with JsonObject

use of com.google.gson.JsonObject in project KeyBox by skavanagh.

the class SessionOutputSerializer method serialize.

@Override
public JsonElement serialize(Object src, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject object = new JsonObject();
    if (typeOfSrc.equals(AuditWrapper.class)) {
        AuditWrapper auditWrapper = (AuditWrapper) src;
        object.addProperty("user_id", auditWrapper.getUser().getId());
        object.addProperty("username", auditWrapper.getUser().getUsername());
        object.addProperty("user_type", auditWrapper.getUser().getUserType());
        object.addProperty("first_nm", auditWrapper.getUser().getFirstNm());
        object.addProperty("last_nm", auditWrapper.getUser().getLastNm());
        object.addProperty("email", auditWrapper.getUser().getEmail());
        object.addProperty("session_id", auditWrapper.getSessionOutput().getSessionId());
        object.addProperty("instance_id", auditWrapper.getSessionOutput().getInstanceId());
        object.addProperty("host_id", auditWrapper.getSessionOutput().getId());
        object.addProperty("host", auditWrapper.getSessionOutput().getDisplayLabel());
        object.addProperty("output", auditWrapper.getSessionOutput().getOutput().toString());
        object.addProperty("timestamp", new Date().getTime());
    }
    return object;
}
Also used : AuditWrapper(com.keybox.manage.model.AuditWrapper) JsonObject(com.google.gson.JsonObject) Date(java.util.Date)

Example 80 with JsonObject

use of com.google.gson.JsonObject in project androidquery by androidquery.

the class AQueryAsyncTest method testAjaxPostRaw.

public void testAjaxPostRaw() throws UnsupportedEncodingException {
    String url = "http://www.androidquery.com/p/doNothing";
    List<NameValuePair> pairs = new ArrayList<NameValuePair>();
    pairs.add(new BasicNameValuePair("q", "androidquery"));
    HttpEntity entity = new UrlEncodedFormEntity(pairs, "UTF-8");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(AQuery.POST_ENTITY, entity);
    aq.ajax(url, params, JSONObject.class, new AjaxCallback<JSONObject>() {

        @Override
        public void callback(String url, JSONObject jo, AjaxStatus status) {
            done(url, jo, status);
        }
    });
    waitAsync();
    JSONObject jo = (JSONObject) result;
    assertNotNull(jo);
    assertNotNull(jo.opt("params"));
    assertEquals("POST", jo.optString("method"));
}
Also used : NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HttpEntity(org.apache.http.HttpEntity) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) JSONObject(org.json.JSONObject) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject) AjaxStatus(com.androidquery.callback.AjaxStatus)

Aggregations

JsonObject (com.google.gson.JsonObject)1417 JsonElement (com.google.gson.JsonElement)389 JsonArray (com.google.gson.JsonArray)293 JsonParser (com.google.gson.JsonParser)285 JsonPrimitive (com.google.gson.JsonPrimitive)137 Gson (com.google.gson.Gson)91 Test (org.junit.Test)81 HashMap (java.util.HashMap)79 Map (java.util.Map)78 ArrayList (java.util.ArrayList)77 IOException (java.io.IOException)66 Test (org.testng.annotations.Test)61 InputStreamReader (java.io.InputStreamReader)38 JsonParseException (com.google.gson.JsonParseException)27 File (java.io.File)25 List (java.util.List)21 HttpResponse (org.apache.http.HttpResponse)21 JsonReader (com.google.gson.stream.JsonReader)19 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)19 InputStream (java.io.InputStream)19