fromJson static method

TaskComment? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static TaskComment? 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'id'), 'Required key "TaskComment[id]" is missing from JSON.');
      assert(json[r'id'] != null, 'Required key "TaskComment[id]" has a null value in JSON.');
      assert(json.containsKey(r'taskId'), 'Required key "TaskComment[taskId]" is missing from JSON.');
      assert(json[r'taskId'] != null, 'Required key "TaskComment[taskId]" has a null value in JSON.');
      assert(json.containsKey(r'content'), 'Required key "TaskComment[content]" is missing from JSON.');
      assert(json[r'content'] != null, 'Required key "TaskComment[content]" has a null value in JSON.');
      assert(json.containsKey(r'createdAt'), 'Required key "TaskComment[createdAt]" is missing from JSON.');
      assert(json[r'createdAt'] != null, 'Required key "TaskComment[createdAt]" has a null value in JSON.');
      assert(json.containsKey(r'updatedAt'), 'Required key "TaskComment[updatedAt]" is missing from JSON.');
      assert(json[r'updatedAt'] != null, 'Required key "TaskComment[updatedAt]" has a null value in JSON.');
      assert(json.containsKey(r'author'), 'Required key "TaskComment[author]" is missing from JSON.');
      assert(json[r'author'] != null, 'Required key "TaskComment[author]" has a null value in JSON.');
      return true;
    }());

    return TaskComment(
      id: mapValueOfType<String>(json, r'id')!,
      taskId: mapValueOfType<String>(json, r'taskId')!,
      content: mapValueOfType<String>(json, r'content')!,
      createdAt: mapDateTime(json, r'createdAt', r'')!,
      updatedAt: mapDateTime(json, r'updatedAt', r'')!,
      author: TaskCommentAuthor.fromJson(json[r'author'])!,
    );
  }
  return null;
}