enumerateConstructorParameters method

void enumerateConstructorParameters (
  1. ClassMirror classMirror,
  2. JsonMap jsonMap,
  3. DeserializationOptions options,
  4. Function filter,
  5. Function visitor
)

Implementation

void enumerateConstructorParameters(ClassMirror classMirror, JsonMap jsonMap,
    DeserializationOptions options, Function filter, Function visitor) {
  final classInfo = ClassInfo(classMirror);
  final classMeta = classInfo.getMeta(options.scheme);
  final methodMirror = classInfo
      .getJsonConstructor(classMeta != null ? classMeta.scheme : null);
  if (methodMirror == null) {
    return;
  }
  methodMirror.parameters.forEach((ParameterMirror param) {
    if (!filter(param)) {
      return;
    }
    final name = param.simpleName;
    final declarationMirror = classInfo.getDeclarationMirror(name) ?? param;
    final paramType = param.hasReflectedType
        ? param.reflectedType
        : param.hasDynamicReflectedType
            ? param.dynamicReflectedType
            : dynamic;
    var paramTypeInfo = getTypeInfo(paramType);
    paramTypeInfo = paramTypeInfo.isDynamic
        ? getTypeInfo(getDeclarationType(declarationMirror))
        : paramTypeInfo;
    var jsonName = name;
    final meta =
        classInfo.getDeclarationMeta(declarationMirror, options.scheme);
    if (meta != null && meta.name != null) {
      jsonName = meta.name;
    }
    jsonName = transformFieldName(jsonName, getCaseStyle(classMeta, options));
    final defaultValue = meta != null ? meta.defaultValue : null;
    var value = jsonMap.hasProperty(jsonName)
        ? jsonMap.getPropertyValue(jsonName) ?? defaultValue
        : defaultValue;
    value = deserializeObject(
        value, DeserializationContext(options, paramTypeInfo.type, meta));
    visitor(param, name, jsonName, classMeta, meta, value, paramTypeInfo);
  });
}