enumeratePublicProperties method

void enumeratePublicProperties (
  1. InstanceMirror instanceMirror,
  2. JsonMap jsonMap,
  3. DeserializationOptions options,
  4. Function visitor
)

Implementation

void enumeratePublicProperties(InstanceMirror instanceMirror, JsonMap jsonMap,
    DeserializationOptions options, Function visitor) {
  final classInfo = ClassInfo(instanceMirror.type);
  final classMeta = classInfo.getMeta(options.scheme);

  for (var name in classInfo.publicFieldNames) {
    var jsonName = name;
    final declarationMirror = classInfo.getDeclarationMirror(name);
    if (declarationMirror == null) {
      continue;
    }
    final declarationType = getDeclarationType(declarationMirror);
    final isGetterOnly = classInfo.isGetterOnly(name);
    final meta =
        classInfo.getDeclarationMeta(declarationMirror, options.scheme);
    if (meta == null && options.processAnnotatedMembersOnly == true) {
      continue;
    }
    if (meta != null && meta.name != null) {
      jsonName = meta.name;
    }
    jsonName = transformFieldName(jsonName, getCaseStyle(classMeta, options));

    dynamic value = instanceMirror.invokeGetter(name);
    if (value == null && jsonMap != null) {
      if (isFieldIgnored(
          jsonMap.getPropertyValue(jsonName), classMeta, meta, options)) {
        continue;
      }
    } else {
      if (isFieldIgnored(value, classMeta, meta, options)) {
        continue;
      }
    }
    visitor(
        name,
        jsonName,
        value,
        isGetterOnly,
        meta,
        getConverter(
            meta, declarationType, value != null ? value.runtimeType : null),
        getScalarType(declarationType),
        getTypeInfo(declarationType));
  }

  classInfo.enumerateJsonGetters((MethodMirror mm, JsonProperty meta) {
    final name = mm.simpleName;
    final value = instanceMirror.invoke(mm.simpleName, []);
    final jsonName =
        transformFieldName(meta.name, getCaseStyle(classMeta, options));
    final declarationType = getDeclarationType(mm);

    if (value == null && jsonMap != null) {
      if (isFieldIgnored(
          jsonMap.getPropertyValue(jsonName), classMeta, meta, options)) {
        return;
      }
    } else {
      if (isFieldIgnored(value, classMeta, meta, options)) {
        return;
      }
    }

    visitor(
        name,
        jsonName,
        value,
        true,
        meta,
        getConverter(
            meta, declarationType, value != null ? value.runtimeType : null),
        getScalarType(declarationType),
        getTypeInfo(declarationType));
  }, options.scheme);
}