fromJson static method

QuestionResult? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static QuestionResult? 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 "QuestionResult[_id]" is missing from JSON.');
      assert(json[r'_id'] != null, 'Required key "QuestionResult[_id]" has a null value in JSON.');
      assert(json.containsKey(r'tenantId'), 'Required key "QuestionResult[tenantId]" is missing from JSON.');
      assert(json[r'tenantId'] != null, 'Required key "QuestionResult[tenantId]" has a null value in JSON.');
      assert(json.containsKey(r'urlId'), 'Required key "QuestionResult[urlId]" is missing from JSON.');
      assert(json[r'urlId'] != null, 'Required key "QuestionResult[urlId]" has a null value in JSON.');
      assert(json.containsKey(r'anonUserId'), 'Required key "QuestionResult[anonUserId]" is missing from JSON.');
      assert(json[r'anonUserId'] != null, 'Required key "QuestionResult[anonUserId]" has a null value in JSON.');
      assert(json.containsKey(r'userId'), 'Required key "QuestionResult[userId]" is missing from JSON.');
      assert(json[r'userId'] != null, 'Required key "QuestionResult[userId]" has a null value in JSON.');
      assert(json.containsKey(r'createdAt'), 'Required key "QuestionResult[createdAt]" is missing from JSON.');
      assert(json[r'createdAt'] != null, 'Required key "QuestionResult[createdAt]" has a null value in JSON.');
      assert(json.containsKey(r'value'), 'Required key "QuestionResult[value]" is missing from JSON.');
      assert(json[r'value'] != null, 'Required key "QuestionResult[value]" has a null value in JSON.');
      assert(json.containsKey(r'questionId'), 'Required key "QuestionResult[questionId]" is missing from JSON.');
      assert(json[r'questionId'] != null, 'Required key "QuestionResult[questionId]" has a null value in JSON.');
      assert(json.containsKey(r'ipHash'), 'Required key "QuestionResult[ipHash]" is missing from JSON.');
      assert(json[r'ipHash'] != null, 'Required key "QuestionResult[ipHash]" has a null value in JSON.');
      return true;
    }());

    return QuestionResult(
      id: mapValueOfType<String>(json, r'_id')!,
      tenantId: mapValueOfType<String>(json, r'tenantId')!,
      urlId: mapValueOfType<String>(json, r'urlId')!,
      anonUserId: mapValueOfType<String>(json, r'anonUserId')!,
      userId: mapValueOfType<String>(json, r'userId')!,
      createdAt: mapDateTime(json, r'createdAt', r'')!,
      value: mapValueOfType<int>(json, r'value')!,
      commentId: mapValueOfType<String>(json, r'commentId'),
      questionId: mapValueOfType<String>(json, r'questionId')!,
      meta: MetaItem.listFromJson(json[r'meta']),
      ipHash: mapValueOfType<String>(json, r'ipHash')!,
    );
  }
  return null;
}