Class MessageTransferObject

java.lang.Object
dev.demeng.pluginbase.redis.MessageTransferObject

public class MessageTransferObject extends Object
The object that wraps an object to be sent across the network, serializable using Gson.
  • Constructor Details

    • MessageTransferObject

      public MessageTransferObject()
  • Method Details

    • of

      public static MessageTransferObject of(@NotNull @NotNull String serverId, @NotNull @NotNull Object obj, long timestamp)
      Wraps the given object to a MessageTransferObject object.
      Parameters:
      serverId - Identifier of the sending server
      obj - Object that should be wrapped
      timestamp - Timestamp of the message
      Returns:
      The serialized object wrapped into a MessageTransferObject
    • toJson

      @Nullable public @Nullable String toJson()
      Converts current data to JSON.
      Returns:
      Object serialized to JSON String
    • fromJson

      @NotNull public static @NotNull Optional<MessageTransferObject> fromJson(@NotNull @NotNull String json)
      Obtains MessageTransferObject from the provided JSON String.
      Parameters:
      json - Serialized MessageTransferObject in JSON String
      Returns:
      Deserialized MessageTransferObject optional
    • parseMessageObject

      @NotNull public <T> @NotNull Optional<T> parseMessageObject(@NotNull @NotNull Class<T> objectType)
      Parses the message string to provided object type.
      Type Parameters:
      T - Type of the object
      Parameters:
      objectType - Class of the object
      Returns:
      Parsed object or null if object cannot be parsed