baseReflectableConverter static method

Map<String, Object?> baseReflectableConverter(
  1. Type originType,
  2. Map<String, Object?> jsonMap,
  3. Map<TypeCheck, Object? Function(dynamic value)> typeMap
)

Implementation

static Map<String, Object?> baseReflectableConverter(Type originType,
    Map<String, Object?> jsonMap,
    Map<TypeCheck, Object? Function(dynamic value)> typeMap) {
  const reflector = Reflector();
  ClassMirror mirror = reflector.reflectType(originType) as ClassMirror;

  mirror.declarations.forEach((key, value) {
    if (value is VariableMirror) {
      var unserializer = typeMap.entries
          .firstWhereOrNull(
              (type) => type.key.matchesType(value.reflectedType))
          ?.value;
      if (unserializer != null) {
        jsonMap[key] = unserializer(jsonMap[key]);
      }
    }
  });

  return jsonMap;
}