$checkedNew<T> function Null safety

T $checkedNew<T>(
  1. String className,
  2. Map map,
  3. T constructor(
      ),
    1. {Map<String, String>? fieldKeyMap}
    )

    Helper function used in generated code when JsonSerializableGenerator.checked is true.

    Should not be used directly.

    Implementation

    T $checkedNew<T>(
      String className,
      Map map,
      T Function() constructor, {
      Map<String, String>? fieldKeyMap,
    }) {
      fieldKeyMap ??= const {};
    
      try {
        return constructor();
      } on CheckedFromJsonException catch (e) {
        if (identical(e.map, map) && e._className == null) {
          e._className = className;
        }
        rethrow;
      } catch (error, stack) {
        String? key;
        if (error is ArgumentError) {
          key = fieldKeyMap[error.name] ?? error.name;
        } else if (error is MissingRequiredKeysException) {
          key = error.missingKeys.first;
        } else if (error is DisallowedNullValueException) {
          key = error.keysWithNullValues.first;
        }
        throw CheckedFromJsonException._(
          error,
          stack,
          map,
          key,
          className: className,
        );
      }
    }