Attachment.fromJson constructor
Returns an Attachment with a filename and the corresponding data
from json
.
Throws a JsonMissingKeyException if there is missing one of the needed
keys (BrokerKeys.filename
, BrokerKeys.data
) in the json
.
Throws a InvalidJsonSchemaException if some values
doesn't match the expected value type string.
Implementation
factory Attachment.fromJson(Map<String, dynamic> json) {
try {
final Attachment attachment = Attachment()
..filename = json.containsKey(BrokerKeys.filename)
? json[BrokerKeys.filename] as String
: throw JsonMissingKeyException(
BrokerKeys.filename, json.toString())
..data = json.containsKey(BrokerKeys.data)
? json[BrokerKeys.data] as String
: throw JsonMissingKeyException(BrokerKeys.data, json.toString());
return attachment;
} on TypeError catch (e) {
throw InvalidJsonSchemaException(
e.stackTrace.toString(), json.toString());
}
}