Search in sources :

Example 46 with JsonParser

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

the class FromJsonDecoder method decodeMessage.

public IBigBlueButtonMessage decodeMessage(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();
            if (PubSubPingMessage.PUBSUB_PING.equals(messageName)) {
                Gson gson = new Gson();
                PubSubPingMessage msg = gson.fromJson(message, PubSubPingMessage.class);
                return msg;
            } else if (PubSubPongMessage.PUBSUB_PONG.equals(messageName)) {
                Gson gson = new Gson();
                PubSubPongMessage msg = gson.fromJson(message, PubSubPongMessage.class);
                return msg;
            } else if (StartCustomPollRequestMessage.START_CUSTOM_POLL_REQUEST.equals(messageName)) {
                Gson gson = new Gson();
                StartCustomPollRequestMessage msg = gson.fromJson(message, StartCustomPollRequestMessage.class);
                return msg;
            } else {
                // System.out.println("Unknown message name=[" + messageName + "]");
                return null;
            }
        }
    }
    System.out.println("Invalid message format");
    return null;
}
Also used : PubSubPongMessage(org.bigbluebutton.common.messages.PubSubPongMessage) PubSubPingMessage(org.bigbluebutton.common.messages.PubSubPingMessage) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) StartCustomPollRequestMessage(org.bigbluebutton.common.messages.StartCustomPollRequestMessage) JsonParser(com.google.gson.JsonParser)

Example 47 with JsonParser

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

the class AllowUserToShareDesktopReply method fromJson.

public static AllowUserToShareDesktopReply 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 (NAME.equals(messageName)) {
                if (payload.has(TIMESTAMP) && payload.has(MEETING_ID) && payload.has(USER_ID) && payload.has(ALLOWED)) {
                    Long timestamp = payload.get(TIMESTAMP).getAsLong();
                    String meetingId = payload.get(MEETING_ID).getAsString();
                    String userId = payload.get(USER_ID).getAsString();
                    Boolean allowed = payload.get(ALLOWED).getAsBoolean();
                    return new AllowUserToShareDesktopReply(meetingId, userId, allowed, timestamp);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 48 with JsonParser

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

the class AssignPresenterRequestMessage method fromJson.

public static AssignPresenterRequestMessage 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 (ASSIGN_PRESENTER_REQUEST.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.NEW_PRESENTER_ID) && payload.has(Constants.NEW_PRESENTER_NAME) && payload.has(Constants.ASSIGNED_BY)) {
                    String meetingId = payload.get(Constants.MEETING_ID).getAsString();
                    String newPresenterId = payload.get(Constants.NEW_PRESENTER_ID).getAsString();
                    String newPresenterName = payload.get(Constants.NEW_PRESENTER_NAME).getAsString();
                    String assignedBy = payload.get(Constants.ASSIGNED_BY).getAsString();
                    return new AssignPresenterRequestMessage(meetingId, newPresenterId, newPresenterName, assignedBy);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 49 with JsonParser

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

the class GetChatHistoryReplyMessage method fromJson.

public static GetChatHistoryReplyMessage 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 (GET_CHAT_HISTORY_REPLY.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.CHAT_HISTORY) && payload.has(Constants.REQUESTER_ID)) {
                    String meetingId = payload.get(Constants.MEETING_ID).getAsString();
                    String requesterId = payload.get(Constants.REQUESTER_ID).getAsString();
                    JsonArray history = (JsonArray) payload.get(Constants.CHAT_HISTORY);
                    Util util = new Util();
                    ArrayList<Map<String, Object>> chatHistory = util.extractChatHistory(history);
                    return new GetChatHistoryReplyMessage(meetingId, requesterId, chatHistory);
                }
            }
        }
    }
    return null;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) Map(java.util.Map) HashMap(java.util.HashMap) JsonParser(com.google.gson.JsonParser)

Example 50 with JsonParser

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

the class GetChatHistoryRequestMessage method fromJson.

public static GetChatHistoryRequestMessage 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 (GET_CHAT_HISTORY_REQUEST.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.REPLY_TO) && payload.has(Constants.REQUESTER_ID)) {
                    String meetingId = payload.get(Constants.MEETING_ID).getAsString();
                    String replyTo = payload.get(Constants.REPLY_TO).getAsString();
                    String requesterId = payload.get(Constants.REQUESTER_ID).getAsString();
                    return new GetChatHistoryRequestMessage(meetingId, requesterId, replyTo);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) 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