Search in sources :

Example 41 with JsonObject

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

the class UndoWhiteboardRequest method fromJson.

public static UndoWhiteboardRequest fromJson(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");
        JsonObject payload = (JsonObject) obj.get("payload");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            if (UNDO_WHITEBOARD_REQUEST.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.WHITEBOARD_ID) && payload.has(Constants.REQUESTER_ID)) {
                    String meetingId = payload.get(Constants.MEETING_ID).getAsString();
                    String whiteboardId = payload.get(Constants.WHITEBOARD_ID).getAsString();
                    String requesterId = payload.get(Constants.REQUESTER_ID).getAsString();
                    return new UndoWhiteboardRequest(meetingId, requesterId, whiteboardId);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 42 with JsonObject

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

the class PresentationPageGeneratedReplyMessage method fromJson.

public static PresentationPageGeneratedReplyMessage fromJson(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");
        JsonObject payload = (JsonObject) obj.get("payload");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            if (PRESENTATION_PAGE_GENERATED.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.CODE) && payload.has(Constants.MESSAGE_KEY) && payload.has(Constants.PRESENTATION_NAME) && payload.has(Constants.NUM_PAGES) && payload.has(Constants.PAGES_COMPLETED) && payload.has(Constants.PRESENTATION_ID)) {
                    String meetingId = payload.get(Constants.MEETING_ID).getAsString();
                    String presentationId = payload.get(Constants.PRESENTATION_ID).getAsString();
                    String presentationName = payload.get(Constants.PRESENTATION_NAME).getAsString();
                    String code = payload.get(Constants.CODE).getAsString();
                    String messageKey = payload.get(Constants.MESSAGE_KEY).getAsString();
                    int numPages = payload.get(Constants.NUM_PAGES).getAsInt();
                    int pagesCompleted = payload.get(Constants.PAGES_COMPLETED).getAsInt();
                    return new PresentationPageGeneratedReplyMessage(meetingId, presentationId, numPages, code, messageKey, presentationName, pagesCompleted);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 43 with JsonObject

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

the class PresentationSharedMessage method fromJson.

public static PresentationSharedMessage fromJson(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");
        JsonObject payload = (JsonObject) obj.get("payload");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            if (PRESENTATION_SHARED_MESSAGE.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.PRESENTATION)) {
                    String meetingId = payload.get(Constants.MEETING_ID).getAsString();
                    JsonObject presentationObject = (JsonObject) payload.get(Constants.PRESENTATION).getAsJsonObject();
                    Util util = new Util();
                    Map<String, Object> presentation = util.extractPresentation(presentationObject);
                    return new PresentationSharedMessage(meetingId, presentation);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 44 with JsonObject

use of com.google.gson.JsonObject in project ion by koush.

the class GsonTests method testParserCastingCallbackError.

public void testParserCastingCallbackError() throws Exception {
    ByteBufferList b = new ByteBufferList(ByteBuffer.wrap("[]".getBytes()));
    FilteredDataEmitter emitter = new FilteredDataEmitter() {

        @Override
        public boolean isPaused() {
            return false;
        }
    };
    GsonObjectParser g = new GsonObjectParser();
    Future<JsonObject> ret = g.parse(emitter);
    emitter.onDataAvailable(emitter, b);
    emitter.getEndCallback().onCompleted(null);
    final Semaphore s = new Semaphore(0);
    ret.setCallback(new FutureCallback<JsonObject>() {

        @Override
        public void onCompleted(Exception e, JsonObject result) {
            assertNull(result);
            assertNotNull(e);
            assertTrue(e instanceof ClassCastException);
            s.release();
        }
    });
    s.acquire();
}
Also used : FilteredDataEmitter(com.koushikdutta.async.FilteredDataEmitter) GsonObjectParser(com.koushikdutta.ion.gson.GsonObjectParser) ByteBufferList(com.koushikdutta.async.ByteBufferList) JsonObject(com.google.gson.JsonObject) Semaphore(java.util.concurrent.Semaphore) JsonParseException(com.google.gson.JsonParseException) ExecutionException(java.util.concurrent.ExecutionException)

Example 45 with JsonObject

use of com.google.gson.JsonObject in project ion by koush.

the class GsonTests method testParserCastingError.

public void testParserCastingError() throws Exception {
    ByteBufferList b = new ByteBufferList(ByteBuffer.wrap("[]".getBytes()));
    FilteredDataEmitter emitter = new FilteredDataEmitter() {

        @Override
        public boolean isPaused() {
            return false;
        }
    };
    GsonObjectParser g = new GsonObjectParser();
    Future<JsonObject> ret = g.parse(emitter);
    emitter.onDataAvailable(emitter, b);
    emitter.getEndCallback().onCompleted(null);
    try {
        JsonObject j = ret.get();
        fail(j.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : FilteredDataEmitter(com.koushikdutta.async.FilteredDataEmitter) GsonObjectParser(com.koushikdutta.ion.gson.GsonObjectParser) ByteBufferList(com.koushikdutta.async.ByteBufferList) JsonObject(com.google.gson.JsonObject) JsonParseException(com.google.gson.JsonParseException) ExecutionException(java.util.concurrent.ExecutionException)

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