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 MessageTransferObjectObtainsMessageTransferObjectfrom provided JSON String.Obtains the content of the transferred messageObtains the server sender identifierlongObtains the timestamp of the message<T> TparseMessageObject(Class<T> objectType) Parses the message string to provided object type.voidsetMessage(String message) Updates the content of the transferred messagevoidsetSenderIdentifier(String senderIdentifier) Changes the server sender identifiervoidsetTimestamp(Long timestamp) Changes the timestamp of the messagetoJson()Converts current data to JSON usingGsonstatic MessageTransferObjectWraps the given object toMessageTransferObjectobject.
-
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
ObtainsMessageTransferObjectfrom provided JSON String.- Parameters:
json- SerializedMessageTransferObjectin JSON String- Returns:
- Deserialized
MessageTransferObject
-
wrap
public static MessageTransferObject wrap(String senderIdentifier, Object objectToWrap, long timestamp) Wraps the given object toMessageTransferObjectobject.- Parameters:
senderIdentifier- Identifier of the sending serverobjectToWrap- Object which shall be wrappedtimestamp- TimeStamp of the message- Returns:
- Instance of
MessageTransferObjectcontaining 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
-