public class ApplicationConversionService extends FormattingConversionService
FormattingConversionService configured by default with
converters and formatters appropriate for most Spring Boot applications.
Designed for direct instantiation but also exposes the static
addApplicationConverters(org.springframework.core.convert.converter.ConverterRegistry) and
addApplicationFormatters(FormatterRegistry) utility methods for ad-hoc use
against registry instance.
| Constructor and Description |
|---|
ApplicationConversionService() |
ApplicationConversionService(StringValueResolver embeddedValueResolver) |
| Modifier and Type | Method and Description |
|---|---|
static void |
addApplicationConverters(ConverterRegistry registry)
Add converters useful for most Spring Boot applications.
|
static void |
addApplicationFormatters(FormatterRegistry registry)
Add formatters useful for most Spring Boot applications.
|
static void |
addBeans(FormatterRegistry registry,
ListableBeanFactory beanFactory)
|
<S,T> void |
addConverter(Class<S> sourceType,
Class<T> targetType,
Converter<? super S,? extends T> converter) |
void |
addConverter(Converter<?,?> converter) |
void |
addConverter(GenericConverter converter) |
void |
addConverterFactory(ConverterFactory<?,?> factory) |
static void |
addDelimitedStringConverters(ConverterRegistry registry)
Add converters to support delimited strings.
|
void |
addFormatter(Formatter<?> formatter) |
void |
addFormatterForFieldAnnotation(AnnotationFormatterFactory<? extends Annotation> annotationFormatterFactory) |
void |
addFormatterForFieldType(Class<?> fieldType,
Formatter<?> formatter) |
void |
addFormatterForFieldType(Class<?> fieldType,
Printer<?> printer,
Parser<?> parser) |
void |
addParser(Parser<?> parser) |
void |
addPrinter(Printer<?> printer) |
static void |
configure(FormatterRegistry registry)
Configure the given
FormatterRegistry with formatters and converters
appropriate for most Spring Boot applications. |
static ConversionService |
getSharedInstance()
Return a shared default application
ConversionService instance, lazily
building it once needed. |
boolean |
isConvertViaObjectSourceType(TypeDescriptor sourceType,
TypeDescriptor targetType)
Return
true if objects of sourceType can be converted to the
targetType and the converter has Object.class as a supported source
type. |
void |
removeConvertible(Class<?> sourceType,
Class<?> targetType) |
setEmbeddedValueResolvercanBypassConvert, canConvert, canConvert, convert, convert, convert, convertNullSource, getConverter, getDefaultConverter, toStringpublic ApplicationConversionService()
public ApplicationConversionService(StringValueResolver embeddedValueResolver)
public void addPrinter(Printer<?> printer)
addPrinter in interface FormatterRegistryaddPrinter in class FormattingConversionServicepublic void addParser(Parser<?> parser)
addParser in interface FormatterRegistryaddParser in class FormattingConversionServicepublic void addFormatter(Formatter<?> formatter)
addFormatter in interface FormatterRegistryaddFormatter in class FormattingConversionServicepublic void addFormatterForFieldType(Class<?> fieldType, Formatter<?> formatter)
addFormatterForFieldType in interface FormatterRegistryaddFormatterForFieldType in class FormattingConversionServicepublic void addConverter(Converter<?,?> converter)
addConverter in interface ConverterRegistryaddConverter in class GenericConversionServicepublic void addFormatterForFieldType(Class<?> fieldType, Printer<?> printer, Parser<?> parser)
addFormatterForFieldType in interface FormatterRegistryaddFormatterForFieldType in class FormattingConversionServicepublic void addFormatterForFieldAnnotation(AnnotationFormatterFactory<? extends Annotation> annotationFormatterFactory)
addFormatterForFieldAnnotation in interface FormatterRegistryaddFormatterForFieldAnnotation in class FormattingConversionServicepublic <S,T> void addConverter(Class<S> sourceType, Class<T> targetType, Converter<? super S,? extends T> converter)
addConverter in interface ConverterRegistryaddConverter in class GenericConversionServicepublic void addConverter(GenericConverter converter)
addConverter in interface ConverterRegistryaddConverter in class GenericConversionServicepublic void addConverterFactory(ConverterFactory<?,?> factory)
addConverterFactory in interface ConverterRegistryaddConverterFactory in class GenericConversionServicepublic void removeConvertible(Class<?> sourceType, Class<?> targetType)
removeConvertible in interface ConverterRegistryremoveConvertible in class GenericConversionServicepublic boolean isConvertViaObjectSourceType(TypeDescriptor sourceType, TypeDescriptor targetType)
true if objects of sourceType can be converted to the
targetType and the converter has Object.class as a supported source
type.sourceType - the source type to testtargetType - the target type to testObjectTo... converterpublic static ConversionService getSharedInstance()
ConversionService instance, lazily
building it once needed.
Note: This method actually returns an ApplicationConversionService
instance. However, the ConversionService signature has been preserved for
binary compatibility.
ApplicationConversionService instance (never
null)public static void configure(FormatterRegistry registry)
FormatterRegistry with formatters and converters
appropriate for most Spring Boot applications.registry - the registry of converters to add to (must also be castable to
ConversionService, e.g. being a ConfigurableConversionService)ClassCastException - if the given FormatterRegistry could not be cast to a
ConversionServicepublic static void addApplicationConverters(ConverterRegistry registry)
registry - the registry of converters to add to (must also be castable to
ConversionService, e.g. being a ConfigurableConversionService)ClassCastException - if the given ConverterRegistry could not be cast to a
ConversionServicepublic static void addDelimitedStringConverters(ConverterRegistry registry)
registry - the registry of converters to add to (must also be castable to
ConversionService, e.g. being a ConfigurableConversionService)ClassCastException - if the given ConverterRegistry could not be cast to a
ConversionServicepublic static void addApplicationFormatters(FormatterRegistry registry)
registry - the service to register default formatters withpublic static void addBeans(FormatterRegistry registry, ListableBeanFactory beanFactory)
registry - the service to register beans withbeanFactory - the bean factory to get the beans from