fromJson static method

CompanyDto? fromJson(
  1. dynamic value
)

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

Implementation

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

    return CompanyDto(
      from: mapValueOfType<int>(json, r'from'),
      to: mapValueOfType<int>(json, r'to'),
      authorisationNr: mapValueOfType<String>(json, r'authorisationNr'),
      vatNr: mapCastOfType<String, String>(json, r'vatNr') ?? const {},
      europeanNr: mapValueOfType<String>(json, r'europeanNr'),
      denomination: mapValueOfType<String>(json, r'denomination'),
      legalForm: mapValueOfType<String>(json, r'legalForm'),
      building: mapValueOfType<String>(json, r'building'),
      streetName: mapValueOfType<String>(json, r'streetName'),
      streetNum: mapValueOfType<String>(json, r'streetNum'),
      postbox: mapValueOfType<String>(json, r'postbox'),
      postcode: mapValueOfType<String>(json, r'postcode'),
      city: mapValueOfType<String>(json, r'city'),
      countryCode: mapValueOfType<String>(json, r'countryCode'),
      phone: mapValueOfType<String>(json, r'phone'),
      language: mapValueOfType<String>(json, r'language'),
      website: mapValueOfType<String>(json, r'website'),
    );
  }
  return null;
}