DefaultConversionService class

A fully configured, ready-to-use conversion service suitable for most Jetleaf environments.

The DefaultConversionService extends SimpleConversionService and provides a comprehensive set of built-in converters for scalar, collection, map, Jetleaf-specific, Dart standard library, object, and temporal types.

Purpose

This service is intended to:

  • Provide a central hub for type conversion throughout Jetleaf applications.
  • Facilitate automatic data transformation for property binding, method argument resolution, serialization, and deserialization.
  • Support custom converters while providing a robust default setup.

Features

  • Singleton shared instance: via getCommonInstance (lazy initialization).
  • Default converters: added on instantiation via addDefaultConverters.
  • Time-aware conversions: includes DateTime, LocalDateTime, ZonedDateTime, LocalDate, LocalTime, Duration, and epoch milliseconds support.
  • Collection conversions: handles List, Set, Queue, Stack, LinkedList, ArrayList, and base types, with nested collection support.
  • Map conversions: generic map-to-map and string-to-map conversions.
  • Jetleaf domain types: Uuid, Currency, Locale, byte arrays via ByteMultiConverter.
  • Dart built-in types: Runes, Symbol, Uri, RegExp, Pattern.
  • Scalar conversions: numbers, booleans, characters, enums, strings.

Lifecycle and Usage

By default, each instance registers converters upon construction. For global access, use getCommonInstance:

final shared = DefaultConversionService.getCommonInstance();
final date = shared.convert<DateTime>("2025-10-27T15:00:00Z");

Alternatively, create individual instances for custom setups:

final service = DefaultConversionService();
service.convert('123', Class.forType(int)); // 123

Extensibility

DefaultConversionService.addScalarConverters(myRegistry);
DefaultConversionService.addTimeConverters(myRegistry);
  • Supports domain-specific and project-specific converters by extending any of the add*Converters static methods.

Conversion Categories

  • Scalar Converters: numbers, booleans, characters, enums, strings, symbols.
  • Time Converters: DateTime, LocalDateTime, LocalDate, LocalTime, ZonedDateTime, Duration, epoch milliseconds.
  • Collection Converters: List, Set, Queue, Stack, LinkedList, ArrayList.
  • Map Converters: generic map transformations and string ↔ map.
  • Jetleaf Converters: Uuid, Currency, Locale, byte arrays.
  • Dart Built-in Converters: Runes, Symbol, Uri, RegExp, Pattern.

Shared Instance Considerations

  • The shared singleton is lazy-initialized and thread-safe.
  • For custom or multi-context setups, prefer constructing individual DefaultConversionService instances.

See Also

Inheritance

Constructors

DefaultConversionService([ProtectionDomain? protectionDomain])
Create a new DefaultConversionService with the set of default converters.

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.
inherited
addConverterFactory(ConverterFactory factory) → void
Registers a ConverterFactory that can produce Converter instances for a target type.
inherited
addNullSourceConverter(GenericNullConverter converter) → void
Adds a new GenericNullConverter to the list of registered converters.
inherited
addPairedConverter(PairedConverter converter) → void
Registers a PairedConverter capable of converting between multiple types.
inherited
addUriValidator(UriValidator validator) → void
Adds a new UriValidator to the list of registered validators.
inherited
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.
inherited
canConvert(Class? sourceType, Class targetType) → bool
Determines whether objects of sourceType can be converted to targetType.
inherited
convert<T>(Object? source, Class<T> targetType, [String? qualifiedName]) → T?
Converts the given source object to the specified targetType.
inherited
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.
inherited
getUriValidators() → List<UriValidator>
Returns a list of registered UriValidator instances.
inherited
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.
inherited
removeNullSourceConverter(GenericNullConverter converter) → void
Removes a registered GenericNullConverter.
inherited
removeUriValidator(UriValidator validator) → void
Removes a registered UriValidator.
inherited
toString() → String
A string representation of this object.
inherited

Operators

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

Static Properties

defaultZone ↔ ZoneId
getter/setter pair

Static Methods

addCollectionConverters(ConverterRegistry registry) → void
Registers common converters for collection types into the given ConverterRegistry.
addDefaultConverters(ConverterRegistry registry) → void
Registers a comprehensive set of converters suitable for most environments.
addJetleafConverters(ConverterRegistry registry) → void
Registers Jetleaf-specific converters into the given ConverterRegistry.
addMapConverters(ConverterRegistry registry) → void
Registers converters for Map types into the given ConverterRegistry.
addOtherDartConverters(ConverterRegistry registry) → void
Registers other Dart built-in type converters into the given ConverterRegistry.
addScalarConverters(ConverterRegistry registry) → void
Registers common scalar converters into the given ConverterRegistry.
addTimeConverters(ConverterRegistry registry) → void
Registers converters for time-related types into the given ConverterRegistry.
getCommonInstance() → ConversionService
Returns a shared default ConversionService instance.