Package org.springframework.boot.convert
Class ApplicationConversionService
java.lang.Object
org.springframework.core.convert.support.GenericConversionService
org.springframework.format.support.FormattingConversionService
org.springframework.boot.convert.ApplicationConversionService
- All Implemented Interfaces:
Aware
,EmbeddedValueResolverAware
,ConversionService
,ConverterRegistry
,ConfigurableConversionService
,FormatterRegistry
A specialization of
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.
- Since:
- 2.0.0
- Author:
- Phillip Webb
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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
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
void
addPrinter
(Printer<?> printer) static void
configure
(FormatterRegistry registry) Configure the givenFormatterRegistry
with formatters and converters appropriate for most Spring Boot applications.static ConversionService
Return a shared default applicationConversionService
instance, lazily building it once needed.boolean
isConvertViaObjectSourceType
(TypeDescriptor sourceType, TypeDescriptor targetType) Returntrue
if objects ofsourceType
can be converted to thetargetType
and the converter hasObject.class
as a supported source type.void
removeConvertible
(Class<?> sourceType, Class<?> targetType) Methods inherited from class org.springframework.format.support.FormattingConversionService
setEmbeddedValueResolver
Methods inherited from class org.springframework.core.convert.support.GenericConversionService
canBypassConvert, canConvert, canConvert, convert, convert, convert, convertNullSource, getConverter, getDefaultConverter, toString
-
Constructor Details
-
ApplicationConversionService
public ApplicationConversionService() -
ApplicationConversionService
-
-
Method Details
-
addPrinter
- Specified by:
addPrinter
in interfaceFormatterRegistry
- Overrides:
addPrinter
in classFormattingConversionService
-
addParser
- Specified by:
addParser
in interfaceFormatterRegistry
- Overrides:
addParser
in classFormattingConversionService
-
addFormatter
- Specified by:
addFormatter
in interfaceFormatterRegistry
- Overrides:
addFormatter
in classFormattingConversionService
-
addFormatterForFieldType
- Specified by:
addFormatterForFieldType
in interfaceFormatterRegistry
- Overrides:
addFormatterForFieldType
in classFormattingConversionService
-
addConverter
- Specified by:
addConverter
in interfaceConverterRegistry
- Overrides:
addConverter
in classGenericConversionService
-
addFormatterForFieldType
- Specified by:
addFormatterForFieldType
in interfaceFormatterRegistry
- Overrides:
addFormatterForFieldType
in classFormattingConversionService
-
addFormatterForFieldAnnotation
public void addFormatterForFieldAnnotation(AnnotationFormatterFactory<? extends Annotation> annotationFormatterFactory) - Specified by:
addFormatterForFieldAnnotation
in interfaceFormatterRegistry
- Overrides:
addFormatterForFieldAnnotation
in classFormattingConversionService
-
addConverter
public <S,T> void addConverter(Class<S> sourceType, Class<T> targetType, Converter<? super S, ? extends T> converter) - Specified by:
addConverter
in interfaceConverterRegistry
- Overrides:
addConverter
in classGenericConversionService
-
addConverter
- Specified by:
addConverter
in interfaceConverterRegistry
- Overrides:
addConverter
in classGenericConversionService
-
addConverterFactory
- Specified by:
addConverterFactory
in interfaceConverterRegistry
- Overrides:
addConverterFactory
in classGenericConversionService
-
removeConvertible
- Specified by:
removeConvertible
in interfaceConverterRegistry
- Overrides:
removeConvertible
in classGenericConversionService
-
isConvertViaObjectSourceType
Returntrue
if objects ofsourceType
can be converted to thetargetType
and the converter hasObject.class
as a supported source type.- Parameters:
sourceType
- the source type to testtargetType
- the target type to test- Returns:
- if conversion happens via an
ObjectTo...
converter - Since:
- 2.4.3
-
configure
Configure the givenFormatterRegistry
with formatters and converters appropriate for most Spring Boot applications.- Parameters:
registry
- the registry of converters to add to (must also be castable to ConversionService, e.g. being aConfigurableConversionService
)- Throws:
ClassCastException
- if the given FormatterRegistry could not be cast to a ConversionService
-
addApplicationConverters
Add converters useful for most Spring Boot applications.- Parameters:
registry
- the registry of converters to add to (must also be castable to ConversionService, e.g. being aConfigurableConversionService
)- Throws:
ClassCastException
- if the given ConverterRegistry could not be cast to a ConversionService
-
addDelimitedStringConverters
Add converters to support delimited strings.- Parameters:
registry
- the registry of converters to add to (must also be castable to ConversionService, e.g. being aConfigurableConversionService
)- Throws:
ClassCastException
- if the given ConverterRegistry could not be cast to a ConversionService
-
addApplicationFormatters
Add formatters useful for most Spring Boot applications.- Parameters:
registry
- the service to register default formatters with
-
addBeans
- Parameters:
registry
- the service to register beans withbeanFactory
- the bean factory to get the beans from- Since:
- 2.2.0
-