getConverter method

ICustomConverter getConverter (
  1. JsonProperty jsonProperty,
  2. Type declarationType,
  3. [Type valueType,
  4. InstanceMirror im]
)

Implementation

ICustomConverter getConverter(JsonProperty jsonProperty, Type declarationType,
    [Type valueType, InstanceMirror im]) {
  var result = jsonProperty != null ? jsonProperty.converter : null;
  var targetType = declarationType;
  if (declarationType == dynamic && valueType != null) {
    targetType = valueType;
  }

  final typeInfo = getTypeInfo(targetType);
  if (result == null && converters[targetType] != null) {
    result = converters[targetType];
  }
  if (result == null &&
      (im != null && im.type != null && im.type.isEnum ||
          typeInfo.isEnum == true)) {
    result = annotatedEnumConverter;
    if (im != null && im.type != null) {
      annotatedEnumConverter.setEnumValues(ClassInfo(im.type).enumValues);
    }
  }
  if (result == null && converters[typeInfo.genericType] != null) {
    result = converters[typeInfo.genericType];
  }
  if (result == null &&
      (jsonProperty != null && jsonProperty.isEnumType(targetType))) {
    result = converters[Enum];
  }
  return result;
}