setFromJson method
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) {
_internalField = null;
_modelValue = null;
if (json is int) _internalField = IntField(parent: parent, options: options);
if (json is double) _internalField = DoubleField(parent: parent, options: options);
if (json is String) _internalField = StringField(parent: parent, options: options);
if (json is bool) _internalField = BoolField(parent: parent, options: options);
if (json is DateTime) _internalField = DateTimeField(parent: parent, options: options);
if (json is List) _internalField = ListField(parent: parent, options: options);
if (json is Map) _internalField = MapField(parent: parent, options: options);
if (json is Model) {
if (json is ModelList) _internalField = ListField(parent: parent, options: options);
if (json is ModelField) _internalField = MapField(parent: parent, options: options);
if (_internalField == null) {
_modelValue = json;
return true;
}
}
_internalField?.setFromJson(json);
return isLoaded;
}