SimpleConversionService class

A comprehensive type conversion service that handles conversion between different types.

This service provides:

  • Registration of converters and converter factories
  • Type conversion with null safety
  • Caching for improved performance
  • Support for primitive type conversions
  • Optional type handling

{@template conversion_service_features}

Key Features

  • Converter registration and management
  • Type hierarchy-aware conversion
  • Null safety and primitive type handling
  • Converter caching for performance
  • Optional type support

Basic Usage

final conversionService = SimpleConversionService();

// Register a converter
conversionService.addConverter(MyConverter());

// Perform conversion
final result = conversionService.convert(source, targetType);

{@endtemplate}

Implemented types
Implementers

Constructors

SimpleConversionService([ProtectionDomain? pd])
Creates a new SimpleConversionService.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addConverter<S, T>(Converter<S, T> converter, {Class<S>? sourceType, Class<T>? targetType}) → void
Registers a simple Converter from one specific source type to one target type.
override
addConverterFactory(ConverterFactory factory) → void
Registers a ConverterFactory that can produce Converter instances for a target type.
override
addNullSourceConverter(GenericNullConverter converter) → void
Adds a new GenericNullConverter to the list of registered converters.
override
addPairedConverter(PairedConverter converter) → void
Registers a PairedConverter capable of converting between multiple types.
override
addUriValidator(UriValidator validator) → void
Adds a new UriValidator to the list of registered validators.
override
canBypassConvert(Class? sourceType, Class targetType) bool
Return whether conversion between the source type and the target type can be bypassed. More precisely, this method will return true if objects of sourceType can be converted to the target type by returning the source object unchanged.
canConvert(Class? sourceType, Class targetType) bool
Determines whether objects of sourceType can be converted to targetType.
override
convert<T>(Object? source, Class<T> targetType, [String? qualifiedName]) → T?
Converts the given source object to the specified targetType.
override
convertTo<T>(Object? source, Class targetType, [Class? sourceType]) Object?
Converts the source object from a known sourceType to a targetType using full type metadata via Class.
override
getUriValidators() List<UriValidator>
Returns a list of registered UriValidator instances.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove(Class sourceType, Class targetType) → void
Removes a registered converter between the specified source and target types.
override
removeNullSourceConverter(GenericNullConverter converter) → void
Removes a registered GenericNullConverter.
override
removeUriValidator(UriValidator validator) → void
Removes a registered UriValidator.
override
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited