fromJson method
O
fromJson(
- Object? json, {
- JsonDecoder? jsonDecoder,
- bool duplicatedEntitiesAsID = true,
- bool? autoResetEntityCache,
override
Returns a class instance from json
.
Implementation
@override
O fromJson(Object? json,
{JsonDecoder? jsonDecoder,
bool duplicatedEntitiesAsID = true,
bool? autoResetEntityCache}) {
if (json == null) {
throw StateError("Null JSON for class: $className");
}
if (json is Map) {
var map = json is Map<String, Object?>
? json
: json.map((k, v) => MapEntry(k.toString(), v));
jsonDecoder ??= JsonDecoder.defaultDecoder;
return jsonDecoder.fromJsonMap<O>(map,
type: classType,
duplicatedEntitiesAsID: duplicatedEntitiesAsID,
autoResetEntityCache: autoResetEntityCache);
} else {
throw StateError(
"JSON needs to be a Map to decode a class (`$className`) object. JSON type: `${json.runtimeType}`");
}
}