fromSerialized function

dynamic fromSerialized (dynamic serialized, dynamic factory)

Converts the serialized value into its respective complex object value depending on the result of the factory function.

example:

fromSerialized({'id': 1, 'name': 'Jhon'}, () => new Person());

fromSerialized([{'id': 1, 'name': 'Jhon'}], [() => new List<Person>(), () => new Person()]);

fromSerialized({'items': [{'id': 1, 'name': 'Jhon'}]},
               [() => new Map<String, List<Person>>(), [() => new List<Person>(), () => new Person()]);

Implementation

fromSerialized(serialized, /*Function | List<Function | List<Function | ...>>*/ factory) {
  if (serialized == null) {
    return serialized;
  } else if (serialized is List) {
    return _fromSerializedIterable(serialized, factory);
  } else if (serialized is Set) {
    return _fromSerializedIterable(serialized, factory);
  } else if (serialized is Map) {
    return _fromSerializedMap(serialized, factory);
  }
}