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) |
setEmbeddedValueResolver
canBypassConvert, canConvert, canConvert, convert, convert, convert, convertNullSource, getConverter, getDefaultConverter, toString
public ApplicationConversionService()
public ApplicationConversionService(StringValueResolver embeddedValueResolver)
public void addPrinter(Printer<?> printer)
addPrinter
in interface FormatterRegistry
addPrinter
in class FormattingConversionService
public void addParser(Parser<?> parser)
addParser
in interface FormatterRegistry
addParser
in class FormattingConversionService
public void addFormatter(Formatter<?> formatter)
addFormatter
in interface FormatterRegistry
addFormatter
in class FormattingConversionService
public void addFormatterForFieldType(Class<?> fieldType, Formatter<?> formatter)
addFormatterForFieldType
in interface FormatterRegistry
addFormatterForFieldType
in class FormattingConversionService
public void addConverter(Converter<?,?> converter)
addConverter
in interface ConverterRegistry
addConverter
in class GenericConversionService
public void addFormatterForFieldType(Class<?> fieldType, Printer<?> printer, Parser<?> parser)
addFormatterForFieldType
in interface FormatterRegistry
addFormatterForFieldType
in class FormattingConversionService
public void addFormatterForFieldAnnotation(AnnotationFormatterFactory<? extends Annotation> annotationFormatterFactory)
addFormatterForFieldAnnotation
in interface FormatterRegistry
addFormatterForFieldAnnotation
in class FormattingConversionService
public <S,T> void addConverter(Class<S> sourceType, Class<T> targetType, Converter<? super S,? extends T> converter)
addConverter
in interface ConverterRegistry
addConverter
in class GenericConversionService
public void addConverter(GenericConverter converter)
addConverter
in interface ConverterRegistry
addConverter
in class GenericConversionService
public void addConverterFactory(ConverterFactory<?,?> factory)
addConverterFactory
in interface ConverterRegistry
addConverterFactory
in class GenericConversionService
public void removeConvertible(Class<?> sourceType, Class<?> targetType)
removeConvertible
in interface ConverterRegistry
removeConvertible
in class GenericConversionService
public 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