setFromJson method

  1. @override
bool setFromJson(
  1. dynamic json
)
override

Convert and set any json to T It doesn't crash if passed incorrect data type value If it fails to put value it returns false

Implementation

@override
bool setFromJson(json) {
  _loaded = false;

  if (json.runtimeType == type) {
    set(json);
  } else if (useModelInstanciator != null) {
    set(useModelInstanciator!.call(json));
    return isLoaded;
  }

  if (_isList) {
    set(ModelList(
      json,
    ));
  } else if (_isMap) {
    set(ModelMap(
      json,
    ));
  } else if (json is Model) {
    final value = Model.createByType(type, json.toJson());
    if (value != null) set(value);
  } else {
    final value = Model.createByType(type, json);
    if (value != null) set(value);
  }

  return isLoaded;
}