public class ApplicationConversionService
extends org.springframework.format.support.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(org.springframework.util.StringValueResolver embeddedValueResolver) |
Modifier and Type | Method and Description |
---|---|
static void |
addApplicationConverters(org.springframework.core.convert.converter.ConverterRegistry registry)
Add converters useful for most Spring Boot applications.
|
static void |
addApplicationFormatters(org.springframework.format.FormatterRegistry registry)
Add formatters useful for most Spring Boot applications.
|
static void |
addBeans(org.springframework.format.FormatterRegistry registry,
org.springframework.beans.factory.ListableBeanFactory beanFactory)
Add
GenericConverter , Converter , Printer , Parser
and Formatter beans from the specified context. |
<S,T> void |
addConverter(java.lang.Class<S> sourceType,
java.lang.Class<T> targetType,
org.springframework.core.convert.converter.Converter<? super S,? extends T> converter) |
void |
addConverter(org.springframework.core.convert.converter.Converter<?,?> converter) |
void |
addConverter(org.springframework.core.convert.converter.GenericConverter converter) |
void |
addConverterFactory(org.springframework.core.convert.converter.ConverterFactory<?,?> factory) |
static void |
addDelimitedStringConverters(org.springframework.core.convert.converter.ConverterRegistry registry)
Add converters to support delimited strings.
|
void |
addFormatter(org.springframework.format.Formatter<?> formatter) |
void |
addFormatterForFieldAnnotation(org.springframework.format.AnnotationFormatterFactory<? extends java.lang.annotation.Annotation> annotationFormatterFactory) |
void |
addFormatterForFieldType(java.lang.Class<?> fieldType,
org.springframework.format.Formatter<?> formatter) |
void |
addFormatterForFieldType(java.lang.Class<?> fieldType,
org.springframework.format.Printer<?> printer,
org.springframework.format.Parser<?> parser) |
void |
addParser(org.springframework.format.Parser<?> parser) |
void |
addPrinter(org.springframework.format.Printer<?> printer) |
static void |
configure(org.springframework.format.FormatterRegistry registry)
Configure the given
FormatterRegistry with formatters and converters
appropriate for most Spring Boot applications. |
static org.springframework.core.convert.ConversionService |
getSharedInstance()
Return a shared default application
ConversionService instance, lazily
building it once needed. |
boolean |
isConvertViaObjectSourceType(org.springframework.core.convert.TypeDescriptor sourceType,
org.springframework.core.convert.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(java.lang.Class<?> sourceType,
java.lang.Class<?> targetType) |
setEmbeddedValueResolver
public ApplicationConversionService()
public ApplicationConversionService(org.springframework.util.StringValueResolver embeddedValueResolver)
public void addPrinter(org.springframework.format.Printer<?> printer)
addPrinter
in interface org.springframework.format.FormatterRegistry
addPrinter
in class org.springframework.format.support.FormattingConversionService
public void addParser(org.springframework.format.Parser<?> parser)
addParser
in interface org.springframework.format.FormatterRegistry
addParser
in class org.springframework.format.support.FormattingConversionService
public void addFormatter(org.springframework.format.Formatter<?> formatter)
addFormatter
in interface org.springframework.format.FormatterRegistry
addFormatter
in class org.springframework.format.support.FormattingConversionService
public void addFormatterForFieldType(java.lang.Class<?> fieldType, org.springframework.format.Formatter<?> formatter)
addFormatterForFieldType
in interface org.springframework.format.FormatterRegistry
addFormatterForFieldType
in class org.springframework.format.support.FormattingConversionService
public void addConverter(org.springframework.core.convert.converter.Converter<?,?> converter)
addConverter
in interface org.springframework.core.convert.converter.ConverterRegistry
addConverter
in class org.springframework.core.convert.support.GenericConversionService
public void addFormatterForFieldType(java.lang.Class<?> fieldType, org.springframework.format.Printer<?> printer, org.springframework.format.Parser<?> parser)
addFormatterForFieldType
in interface org.springframework.format.FormatterRegistry
addFormatterForFieldType
in class org.springframework.format.support.FormattingConversionService
public void addFormatterForFieldAnnotation(org.springframework.format.AnnotationFormatterFactory<? extends java.lang.annotation.Annotation> annotationFormatterFactory)
addFormatterForFieldAnnotation
in interface org.springframework.format.FormatterRegistry
addFormatterForFieldAnnotation
in class org.springframework.format.support.FormattingConversionService
public <S,T> void addConverter(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, org.springframework.core.convert.converter.Converter<? super S,? extends T> converter)
addConverter
in interface org.springframework.core.convert.converter.ConverterRegistry
addConverter
in class org.springframework.core.convert.support.GenericConversionService
public void addConverter(org.springframework.core.convert.converter.GenericConverter converter)
addConverter
in interface org.springframework.core.convert.converter.ConverterRegistry
addConverter
in class org.springframework.core.convert.support.GenericConversionService
public void addConverterFactory(org.springframework.core.convert.converter.ConverterFactory<?,?> factory)
addConverterFactory
in interface org.springframework.core.convert.converter.ConverterRegistry
addConverterFactory
in class org.springframework.core.convert.support.GenericConversionService
public void removeConvertible(java.lang.Class<?> sourceType, java.lang.Class<?> targetType)
removeConvertible
in interface org.springframework.core.convert.converter.ConverterRegistry
removeConvertible
in class org.springframework.core.convert.support.GenericConversionService
public boolean isConvertViaObjectSourceType(org.springframework.core.convert.TypeDescriptor sourceType, org.springframework.core.convert.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 org.springframework.core.convert.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(org.springframework.format.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
)java.lang.ClassCastException
- if the given FormatterRegistry could not be cast to a
ConversionServicepublic static void addApplicationConverters(org.springframework.core.convert.converter.ConverterRegistry registry)
registry
- the registry of converters to add to (must also be castable to
ConversionService, e.g. being a ConfigurableConversionService
)java.lang.ClassCastException
- if the given ConverterRegistry could not be cast to a
ConversionServicepublic static void addDelimitedStringConverters(org.springframework.core.convert.converter.ConverterRegistry registry)
registry
- the registry of converters to add to (must also be castable to
ConversionService, e.g. being a ConfigurableConversionService
)java.lang.ClassCastException
- if the given ConverterRegistry could not be cast to a
ConversionServicepublic static void addApplicationFormatters(org.springframework.format.FormatterRegistry registry)
registry
- the service to register default formatters withpublic static void addBeans(org.springframework.format.FormatterRegistry registry, org.springframework.beans.factory.ListableBeanFactory beanFactory)
GenericConverter
, Converter
, Printer
, Parser
and Formatter
beans from the specified context.registry
- the service to register beans withbeanFactory
- the bean factory to get the beans from