detectObjectType method

TypeInfo detectObjectType (
  1. dynamic objectInstance,
  2. Type objectType,
  3. JsonMap objectJsonMap,
  4. DeserializationOptions options
)

Implementation

TypeInfo detectObjectType(dynamic objectInstance, Type objectType,
    JsonMap objectJsonMap, DeserializationOptions options) {
  final objectClassMirror = classes[objectType.toString()];
  final objectClassInfo = ClassInfo(objectClassMirror);
  final Json meta = objectClassInfo.metaData
      .firstWhere((m) => m is Json, orElse: () => null);

  if (objectInstance is Map<String, dynamic>) {
    objectJsonMap = JsonMap(objectInstance, meta);
  }
  final typeInfo = getTypeInfo(objectType ?? objectInstance.runtimeType);

  final typeNameProperty = getTypeNameProperty(meta, options);
  final String typeName = objectJsonMap != null &&
          typeNameProperty != null &&
          objectJsonMap.hasProperty(typeNameProperty)
      ? objectJsonMap.getPropertyValue(typeNameProperty)
      : typeInfo.typeName;

  final type = classes[typeName] != null
      ? classes[typeName].reflectedType
      : typeInfo.type;
  return getTypeInfo(type);
}