fromJson static method

RenderableUserNotification? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static RenderableUserNotification? 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(() {
      assert(json.containsKey(r'optedOut'), 'Required key "RenderableUserNotification[optedOut]" is missing from JSON.');
      assert(json[r'optedOut'] != null, 'Required key "RenderableUserNotification[optedOut]" has a null value in JSON.');
      assert(json.containsKey(r'type'), 'Required key "RenderableUserNotification[type]" is missing from JSON.');
      assert(json[r'type'] != null, 'Required key "RenderableUserNotification[type]" has a null value in JSON.');
      assert(json.containsKey(r'createdAt'), 'Required key "RenderableUserNotification[createdAt]" is missing from JSON.');
      assert(json[r'createdAt'] != null, 'Required key "RenderableUserNotification[createdAt]" has a null value in JSON.');
      assert(json.containsKey(r'sent'), 'Required key "RenderableUserNotification[sent]" is missing from JSON.');
      assert(json[r'sent'] != null, 'Required key "RenderableUserNotification[sent]" has a null value in JSON.');
      assert(json.containsKey(r'viewed'), 'Required key "RenderableUserNotification[viewed]" is missing from JSON.');
      assert(json[r'viewed'] != null, 'Required key "RenderableUserNotification[viewed]" has a null value in JSON.');
      assert(json.containsKey(r'relatedObjectId'), 'Required key "RenderableUserNotification[relatedObjectId]" is missing from JSON.');
      assert(json[r'relatedObjectId'] != null, 'Required key "RenderableUserNotification[relatedObjectId]" has a null value in JSON.');
      assert(json.containsKey(r'relatedObjectType'), 'Required key "RenderableUserNotification[relatedObjectType]" is missing from JSON.');
      assert(json[r'relatedObjectType'] != null, 'Required key "RenderableUserNotification[relatedObjectType]" has a null value in JSON.');
      assert(json.containsKey(r'url'), 'Required key "RenderableUserNotification[url]" is missing from JSON.');
      assert(json[r'url'] != null, 'Required key "RenderableUserNotification[url]" has a null value in JSON.');
      assert(json.containsKey(r'urlId'), 'Required key "RenderableUserNotification[urlId]" is missing from JSON.');
      assert(json[r'urlId'] != null, 'Required key "RenderableUserNotification[urlId]" has a null value in JSON.');
      assert(json.containsKey(r'_id'), 'Required key "RenderableUserNotification[_id]" is missing from JSON.');
      assert(json[r'_id'] != null, 'Required key "RenderableUserNotification[_id]" has a null value in JSON.');
      return true;
    }());

    return RenderableUserNotification(
      conversationId: mapValueOfType<String>(json, r'conversationId'),
      contextHTML: mapValueOfType<String>(json, r'contextHTML'),
      fromUserNames: json[r'fromUserNames'] is Iterable
          ? (json[r'fromUserNames'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      fromUserIds: json[r'fromUserIds'] is Iterable
          ? (json[r'fromUserIds'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      relatedIds: json[r'relatedIds'] is Iterable
          ? (json[r'relatedIds'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      count: mapValueOfType<int>(json, r'count'),
      optedOut: mapValueOfType<bool>(json, r'optedOut')!,
      fromUserAvatarSrc: mapValueOfType<String>(json, r'fromUserAvatarSrc'),
      fromUserId: mapValueOfType<String>(json, r'fromUserId'),
      fromUserName: mapValueOfType<String>(json, r'fromUserName'),
      fromCommentId: mapValueOfType<String>(json, r'fromCommentId'),
      type: NotificationType.fromJson(json[r'type'])!,
      createdAt: mapValueOfType<String>(json, r'createdAt')!,
      sent: mapValueOfType<String>(json, r'sent')!,
      viewed: mapValueOfType<String>(json, r'viewed')!,
      relatedObjectId: mapValueOfType<String>(json, r'relatedObjectId')!,
      relatedObjectType: NotificationObjectType.fromJson(json[r'relatedObjectType'])!,
      pageTitle: mapValueOfType<String>(json, r'pageTitle'),
      url: mapValueOfType<String>(json, r'url')!,
      urlId: mapValueOfType<String>(json, r'urlId')!,
      id: mapValueOfType<String>(json, r'_id')!,
    );
  }
  return null;
}