Top Description Fields Constructors Methods
org.springframework.core.convert.support

public Class DefaultConversionService

extends GenericConversionService
Class Inheritance
Imports
java.nio.charset.Charset, java.util.Currency, .Locale, .UUID, java.util.regex.Pattern, org.springframework.core.KotlinDetector, org.springframework.core.convert.ConversionService, org.springframework.core.convert.converter.ConverterRegistry, org.springframework.lang.Nullable

A specialization of GenericConversionService configured by default with converters appropriate for most environments.

Designed for direct instantiation but also exposes the static addDefaultConverters(ConverterRegistry) utility method for ad-hoc use against any ConverterRegistry instance.

Authors
Chris Beams, Juergen Hoeller, Stephane Nicoll
Since
3.1

Field Summary

Modifier and TypeField and Description
private static volatile DefaultConversionService

Constructor Summary

AccessConstructor and Description
public
DefaultConversionService()

Create a new DefaultConversionService with the set of default converters.

Method Summary

Modifier and TypeMethod and Description
public static void
addCollectionConverters(ConverterRegistry
the registry of converters to add to (must also be castable to ConversionService, e.g. being a ConfigurableConversionService)
converterRegistry
)

Add common collection converters.

public static void
addDefaultConverters(ConverterRegistry
the registry of converters to add to (must also be castable to ConversionService, e.g. being a ConfigurableConversionService)
converterRegistry
)

Add converters appropriate for most environments.

private static void
public static ConversionService

Returns:

the shared ConversionService instance (never null)
getSharedInstance
()

Return a shared default ConversionService instance, lazily building it once needed.

Inherited from org.springframework.core.convert.support.GenericConversionService:
addConverteraddConverteraddConverteraddConverterFactorycanBypassConvertcanConvertcanConvertconvertconvertconvertNullSourcegetConvertergetDefaultConverterremoveConvertibletoString

Field Detail

sharedInstanceback to summary
private static volatile DefaultConversionService sharedInstance
Annotations
@Nullable

Constructor Detail

DefaultConversionServiceback to summary
public DefaultConversionService()

Create a new DefaultConversionService with the set of default converters.

Method Detail

addCollectionConvertersback to summary
public static void addCollectionConverters(ConverterRegistry converterRegistry)

Add common collection converters.

Parameters
converterRegistry:ConverterRegistry

the registry of converters to add to (must also be castable to ConversionService, e.g. being a ConfigurableConversionService)

Exceptions
ClassCastException:
if the given ConverterRegistry could not be cast to a ConversionService
Since
4.2.3
addDefaultConvertersback to summary
public static void addDefaultConverters(ConverterRegistry converterRegistry)

Add converters appropriate for most environments.

Parameters
converterRegistry:ConverterRegistry

the registry of converters to add to (must also be castable to ConversionService, e.g. being a ConfigurableConversionService)

Exceptions
ClassCastException:
if the given ConverterRegistry could not be cast to a ConversionService
addScalarConvertersback to summary
private static void addScalarConverters(ConverterRegistry converterRegistry)
getSharedInstanceback to summary
public static ConversionService getSharedInstance()

Return a shared default ConversionService instance, lazily building it once needed.

Note

We highly recommend constructing individual ConversionService instances for customization purposes. This accessor is only meant as a fallback for code paths which need simple type coercion but cannot access a longer-lived ConversionService instance any other way.

Returns:ConversionService

the shared ConversionService instance (never null)

Since
4.3.5