configureConverter method

void configureConverter (
  1. ICustomConverter converter,
  2. {dynamic value,
  3. SerializationContext serializationContext,
  4. DeserializationContext deserializationContext}
)

Implementation

void configureConverter(ICustomConverter converter,
    {dynamic value,
    SerializationContext serializationContext,
    DeserializationContext deserializationContext}) {
  final typeInfo = deserializationContext != null
      ? getTypeInfo(deserializationContext.instanceType)
      : null;

  if (converter is ICustomIterableConverter) {
    (converter as ICustomIterableConverter)
        .setIterableInstance(value, typeInfo);
  }
  if (converter is ICustomMapConverter) {
    final instance = value ??
        (deserializationContext != null
            ? deserializationContext.options.template
            : null);
    (converter as ICustomMapConverter).setMapInstance(instance, typeInfo);
  }
  if (converter is IRecursiveConverter) {
    (converter as IRecursiveConverter).setSerializeObjectFunction(
        (o) => serializeObject(o, serializationContext));
    (converter as IRecursiveConverter).setDeserializeObjectFunction(
        (o, type) => deserializeObject(
            o,
            DeserializationContext(deserializationContext.options, type,
                deserializationContext.parentMeta)));
  }
}