fromJson static method

Log? fromJson(
  1. dynamic value
)

Returns a new Log instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static Log? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      requiredKeys.forEach((key) {
        assert(json.containsKey(key),
            'Required key "Log[$key]" is missing from JSON.');
        assert(json[key] != null,
            'Required key "Log[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return Log(
      timestamp: mapDateTime(json, r'timestamp', '')!,
      flowId: mapValueOfType<int>(json, r'flowId')!,
      srcIp: mapValueOfType<String>(json, r'srcIp')!,
      srcPort: mapValueOfType<int>(json, r'srcPort')!,
      dstIp: mapValueOfType<String>(json, r'dstIp')!,
      dstPort: mapValueOfType<int>(json, r'dstPort')!,
      protoLv4: ProtocolL4.fromJson(json[r'protoLv4'])!,
      protoLv7: ProtocolL7.fromJson(json[r'protoLv7'])!,
      action: mapValueOfType<String>(json, r'action')!,
      signature: mapValueOfType<String>(json, r'signature')!,
      category: mapValueOfType<String>(json, r'category')!,
      payload: mapValueOfType<Object>(json, r'payload')!,
    );
  }
  return null;
}