fromJsonOrNull static method

GenerateDartModel? fromJsonOrNull(
  1. Map<String, dynamic>? json
)

Constructs a new instance of GenerateDartModel, from json, which must be a valid JSON object. Returns null if json is null or if the conversion fails.

Implementation

static GenerateDartModel? fromJsonOrNull(
  Map<String, dynamic>? json,
) {
  try {
    final className = json?['className']?.toString().trim().nullIfEmpty;
    final fields = letSetOrNull<dynamic>(json?['fields'])
        ?.map(
          (p0) => p0,
        )
        .nonNulls
        .nullIfEmpty
        ?.toSet()
        .unmodifiable;
    final shouldInherit = letAsOrNull<bool>(json?['shouldInherit']);
    final inheritanceConstructor =
        json?['inheritanceConstructor']?.toString().trim().nullIfEmpty;
    final keyStringCase =
        json?['keyStringCase']?.toString().trim().nullIfEmpty;
    final description = json?['description']?.toString().trim().nullIfEmpty;
    return GenerateDartModel(
      className: className,
      fields: fields,
      shouldInherit: shouldInherit,
      inheritanceConstructor: inheritanceConstructor,
      keyStringCase: keyStringCase,
      description: description,
    );
  } catch (e) {
    return null;
  }
}