Class MessageTransferObject
java.lang.Object
cz.foresttech.forestredis.shared.models.MessageTransferObject
DTO object used for sending data across network. Supports
custom object serialization using
Gson
.-
Constructor Summary
ConstructorsConstructorDescriptionEmpty constructor in case of using setters to add data laterMessageTransferObject
(String senderIdentifier, String message, long timestamp) Constructs the instance with provided parameters -
Method Summary
Modifier and TypeMethodDescriptionstatic MessageTransferObject
ObtainsMessageTransferObject
from provided JSON String.Obtains the content of the transferred messageObtains the server sender identifierlong
Obtains the timestamp of the message<T> T
parseMessageObject
(Class<T> objectType) Parses the message string to provided object type.void
setMessage
(String message) Updates the content of the transferred messagevoid
setSenderIdentifier
(String senderIdentifier) Changes the server sender identifiervoid
setTimestamp
(Long timestamp) Changes the timestamp of the messagetoJson()
Converts current data to JSON usingGson
static MessageTransferObject
Wraps the given object toMessageTransferObject
object.
-
Constructor Details
-
MessageTransferObject
public MessageTransferObject()Empty constructor in case of using setters to add data later -
MessageTransferObject
Constructs the instance with provided parameters- Parameters:
senderIdentifier
- Identifier of sending servermessage
- Message contenttimestamp
- TimeStamp of the message
-
-
Method Details
-
toJson
Converts current data to JSON usingGson
- Returns:
- Object serialized to JSON String
-
fromJson
ObtainsMessageTransferObject
from provided JSON String.- Parameters:
json
- SerializedMessageTransferObject
in JSON String- Returns:
- Deserialized
MessageTransferObject
-
wrap
public static MessageTransferObject wrap(String senderIdentifier, Object objectToWrap, long timestamp) Wraps the given object toMessageTransferObject
object.- Parameters:
senderIdentifier
- Identifier of the sending serverobjectToWrap
- Object which shall be wrappedtimestamp
- TimeStamp of the message- Returns:
- Instance of
MessageTransferObject
containing serialized object from input
-
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
-
getTimestamp
public long getTimestamp()Obtains the timestamp of the message- Returns:
- Date when message has been sent
-
setTimestamp
Changes the timestamp of the message- Parameters:
timestamp
- New date when the message has been sent
-
getSenderIdentifier
Obtains the server sender identifier- Returns:
- Server identifier of the sender
-
getMessage
Obtains the content of the transferred message- Returns:
- Content of the message
-
setSenderIdentifier
Changes the server sender identifier- Parameters:
senderIdentifier
- New server sender identifier
-
setMessage
Updates the content of the transferred message- Parameters:
message
- New transferred message content
-