UserMessage.fromJson constructor
Creates a UserMessage with the information stored in the json
.
Throws a JsonMissingKeyException if there is missing one of the needed
keys (BrokerKeys.identifier
, BrokerKeys.receivers
,BrokerKeys.sender
)
in the json
.
Throws a InvalidJsonSchemaException if some values
doesn't match the expected value type.
Implementation
factory UserMessage.fromJson(Map<String, dynamic> json) {
try {
final UserMessage msg = UserMessage()
..generateFromJson(json)
..attachment = json.containsKey(BrokerKeys.attachments)
? Attachment.fromJson(
json[BrokerKeys.attachments] as Map<String, dynamic>)
: null
..subject = json[BrokerKeys.subject] as String?
..text = json[BrokerKeys.text] as String?;
return msg;
} on TypeError catch (e) {
throw InvalidJsonSchemaException(
e.stackTrace.toString(), json.toString());
}
}