Package dev.demeng.pluginbase.redis
Class MessageTransferObject
java.lang.Object
dev.demeng.pluginbase.redis.MessageTransferObject
The object that wraps an object to be sent across the network, serializable using
Gson.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull Optional<MessageTransferObject>ObtainsMessageTransferObjectfrom the provided JSON String.static MessageTransferObjectWraps the given object to aMessageTransferObjectobject.<T> @NotNull Optional<T>parseMessageObject(@NotNull Class<T> objectType) Parses the message string to provided object type.@Nullable StringtoJson()Converts current data to JSON.
-
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 aMessageTransferObjectobject.- Parameters:
serverId- Identifier of the sending serverobj- Object that should be wrappedtimestamp- Timestamp of the message- Returns:
- The serialized object wrapped into a
MessageTransferObject
-
toJson
Converts current data to JSON.- Returns:
- Object serialized to JSON String
-
fromJson
@NotNull public static @NotNull Optional<MessageTransferObject> fromJson(@NotNull @NotNull String json) ObtainsMessageTransferObjectfrom the provided JSON String.- Parameters:
json- SerializedMessageTransferObjectin JSON String- Returns:
- Deserialized
MessageTransferObjectoptional
-
parseMessageObject
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
-