Search in sources :

Example 41 with JsonParser

use of com.google.gson.JsonParser 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 JsonParser

use of com.google.gson.JsonParser 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 JsonParser

use of com.google.gson.JsonParser 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 JsonParser

use of com.google.gson.JsonParser in project commons by twitter.

the class JsonCodecTest method testExpectedFormat.

@Test
public void testExpectedFormat() throws IOException {
    Codec<TestClass> codec = JsonCodec.create(TestClass.class);
    TestClass item = createTestClassInstance();
    JsonElement expectedElement = new JsonParser().parse("{\"data1\":\"foo\",\"data2\":\"bar\",\"data3\":42,\"data4\":[\"abc\",\"def\"]}");
    JsonElement actualElement = new JsonParser().parse(new String(serialize(codec, item), "utf-8"));
    assertEquals(expectedElement.toString(), actualElement.toString());
}
Also used : JsonElement(com.google.gson.JsonElement) JsonParser(com.google.gson.JsonParser) Test(org.junit.Test)

Example 45 with JsonParser

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

the class WhiteboardMessageReceiver method handleMessage.

@Override
public void handleMessage(String pattern, String channel, String message) {
    if (channel.equalsIgnoreCase(MessagingConstants.TO_WHITEBOARD_CHANNEL)) {
        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();
                if (UndoWhiteboardRequest.UNDO_WHITEBOARD_REQUEST.equals(messageName)) {
                    UndoWhiteboardRequest msg = UndoWhiteboardRequest.fromJson(message);
                    bbbInGW.undoWhiteboard(msg.meetingId, msg.requesterId, msg.whiteboardId);
                } else if (ClearWhiteboardRequestMessage.CLEAR_WHITEBOARD_REQUEST.equals(messageName)) {
                    ClearWhiteboardRequestMessage msg = ClearWhiteboardRequestMessage.fromJson(message);
                    bbbInGW.clearWhiteboard(msg.meetingId, msg.requesterId, msg.whiteboardId);
                } else if (RequestWhiteboardAnnotationHistoryRequestMessage.REQUEST_WHITEBOARD_ANNOTATION_HISTORY_REQUEST.equals(messageName)) {
                    RequestWhiteboardAnnotationHistoryRequestMessage msg = RequestWhiteboardAnnotationHistoryRequestMessage.fromJson(message);
                    bbbInGW.requestWhiteboardAnnotationHistory(msg.meetingId, msg.requesterId, msg.whiteboardId, msg.replyTo);
                } else if (IsWhiteboardEnabledRequestMessage.IS_WHITEBOARD_ENABLED_REQUEST.equals(messageName)) {
                    IsWhiteboardEnabledRequestMessage msg = IsWhiteboardEnabledRequestMessage.fromJson(message);
                    bbbInGW.isWhiteboardEnabled(msg.meetingId, msg.requesterId, msg.replyTo);
                } else if (EnableWhiteboardRequestMessage.ENABLE_WHITEBOARD_REQUEST.equals(messageName)) {
                    EnableWhiteboardRequestMessage msg = EnableWhiteboardRequestMessage.fromJson(message);
                    bbbInGW.enableWhiteboard(msg.meetingId, msg.requesterId, msg.enable);
                } else if (SendWhiteboardAnnotationRequestMessage.SEND_WHITEBOARD_ANNOTATION_REQUEST.equals(messageName)) {
                    SendWhiteboardAnnotationRequestMessage msg = SendWhiteboardAnnotationRequestMessage.fromJson(message);
                    bbbInGW.sendWhiteboardAnnotation(msg.meetingId, msg.requesterId, msg.annotation);
                }
            }
        }
    }
}
Also used : EnableWhiteboardRequestMessage(org.bigbluebutton.common.messages.EnableWhiteboardRequestMessage) RequestWhiteboardAnnotationHistoryRequestMessage(org.bigbluebutton.common.messages.RequestWhiteboardAnnotationHistoryRequestMessage) SendWhiteboardAnnotationRequestMessage(org.bigbluebutton.common.messages.SendWhiteboardAnnotationRequestMessage) JsonObject(com.google.gson.JsonObject) UndoWhiteboardRequest(org.bigbluebutton.common.messages.UndoWhiteboardRequest) ClearWhiteboardRequestMessage(org.bigbluebutton.common.messages.ClearWhiteboardRequestMessage) IsWhiteboardEnabledRequestMessage(org.bigbluebutton.common.messages.IsWhiteboardEnabledRequestMessage) JsonParser(com.google.gson.JsonParser)

Aggregations

JsonParser (com.google.gson.JsonParser)356 JsonObject (com.google.gson.JsonObject)285 JsonElement (com.google.gson.JsonElement)105 JsonArray (com.google.gson.JsonArray)57 IOException (java.io.IOException)43 Gson (com.google.gson.Gson)40 InputStreamReader (java.io.InputStreamReader)32 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)20 Map (java.util.Map)18 Type (java.lang.reflect.Type)15 JsonReader (com.google.gson.stream.JsonReader)12 Test (org.junit.Test)12 URL (java.net.URL)11 AssetManager (android.content.res.AssetManager)10 InputStream (java.io.InputStream)10 GsonBuilder (com.google.gson.GsonBuilder)9 UserType (com.glitchcog.fontificator.bot.UserType)8 EmojiType (com.glitchcog.fontificator.emoji.EmojiType)8 JsonParseException (com.google.gson.JsonParseException)8