fromJson static method

CustomerJobPostCreate? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static CustomerJobPostCreate? 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 "CustomerJobPostCreate[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "CustomerJobPostCreate[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return CustomerJobPostCreate(
      id: mapValueOfType<int>(json, r'id'),
      createdBy: mapValueOfType<int>(json, r'created_by'),
      clientName: mapValueOfType<String>(json, r'client_name')!,
      clientEmail: mapValueOfType<String>(json, r'client_email')!,
      clientPhoneNumber: mapValueOfType<String>(json, r'client_phone_number') ?? '',
      postcode: mapValueOfType<String>(json, r'postcode'),
      fullAddress: mapValueOfType<String>(json, r'full_address')!,
      subject: mapValueOfType<int>(json, r'subject'),
      level: mapValueOfType<int>(json, r'level'),
      description: mapValueOfType<String>(json, r'description'),
      studentAvailability: JobPostAvailability.listFromJson(json[r'student_availability']),
      studentPersonality: json[r'student_personality'] is Iterable
          ? (json[r'student_personality'] as Iterable).cast<int>().toList(growable: false)
          : const [],
      priceMin: mapValueOfType<int>(json, r'price_min'),
      priceMax: mapValueOfType<int>(json, r'price_max'),
      tags: json[r'tags'] is Iterable
          ? (json[r'tags'] as Iterable).cast<String>().toList(growable: false)
          : const [],
    );
  }
  return null;
}