generateFromJson method

void generateFromJson(
  1. Map<String, dynamic> json
)
inherited

Fills this Message with the information stored in the json.

Throws a JsonMissingKeyException if there is missing one of the needed keys (BrokerKeys.identifier,BrokerKeys.sender) in the json. Throws a InvalidJsonSchemaException if some values doesn't match the expected value type.

Implementation

void generateFromJson(Map<String, dynamic> json) {
  try {
    _identifier = json.containsKey(BrokerKeys.identifier)
        ? json[BrokerKeys.identifier] as String
        : throw JsonMissingKeyException(
            BrokerKeys.identifier, json.toString());
    sender = json.containsKey(BrokerKeys.sender)
        ? json[BrokerKeys.sender] as String
        : throw JsonMissingKeyException(BrokerKeys.sender, json.toString());
    receivers = json.containsKey(BrokerKeys.receivers)
        ? _createReceiversSet(json[BrokerKeys.receivers] as List<dynamic>)
        : const <String>{};
    replyingToMessage = json[BrokerKeys.replyingToMessage] as String?;
    replyToEndpoint = json[BrokerKeys.replyToEndpoint] as String?;
  } on TypeError catch (e) {
    throw InvalidJsonSchemaException(
        e.stackTrace.toString(), json.toString());
  }
}