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(ConverterRegistry) and
addApplicationFormatters(FormatterRegistry) utility methods for ad-hoc use
against registry instance.
- Since:
- 2.0.0
- Author:
- Phillip Webb, Shixiong Guo
-
Constructor Summary
ConstructorsConstructorDescriptionApplicationConversionService(@Nullable StringValueResolver embeddedValueResolver) -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddApplicationConverters(ConverterRegistry registry) Add converters useful for most Spring Boot applications.static voidaddApplicationFormatters(FormatterRegistry registry) Add formatters useful for most Spring Boot applications.static voidaddBeans(FormatterRegistry registry, ListableBeanFactory beanFactory) AddPrinter,Parser,Formatter,Converter,ConverterFactory,GenericConverter, and beans from the specified bean factory.addBeans(FormatterRegistry registry, ListableBeanFactory beanFactory, @Nullable String qualifier) AddPrinter,Parser,Formatter,Converter,ConverterFactory,GenericConverter, and beans from the specified bean factory.<S,T> void addConverter(Class<S> sourceType, Class<T> targetType, Converter<? super S, ? extends T> converter) voidaddConverter(Converter<?, ?> converter) voidaddConverter(GenericConverter converter) voidaddConverterFactory(ConverterFactory<?, ?> factory) static voidAdd converters to support delimited strings.voidaddFormatter(Formatter<?> formatter) voidaddFormatterForFieldAnnotation(AnnotationFormatterFactory<? extends Annotation> annotationFormatterFactory) voidaddFormatterForFieldType(Class<?> fieldType, Formatter<?> formatter) voidaddFormatterForFieldType(Class<?> fieldType, Printer<?> printer, Parser<?> parser) voidvoidaddPrinter(Printer<?> printer) static voidconfigure(FormatterRegistry registry) Configure the givenFormatterRegistrywith formatters and converters appropriate for most Spring Boot applications.static ConversionServiceReturn a shared default applicationConversionServiceinstance, lazily building it once needed.booleanisConvertViaObjectSourceType(TypeDescriptor sourceType, TypeDescriptor targetType) Returntrueif objects ofsourceTypecan be converted to thetargetTypeand the converter hasObject.classas a supported source type.voidremoveConvertible(Class<?> sourceType, Class<?> targetType) Methods inherited from class FormattingConversionService
setEmbeddedValueResolverMethods inherited from class GenericConversionService
canBypassConvert, canConvert, canConvert, convert, convert, convertNullSource, getConverter, getDefaultConverter, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ConversionService
convert
-
Constructor Details
-
ApplicationConversionService
public ApplicationConversionService() -
ApplicationConversionService
-
-
Method Details
-
addPrinter
- Specified by:
addPrinterin interfaceFormatterRegistry- Overrides:
addPrinterin classFormattingConversionService
-
addParser
- Specified by:
addParserin interfaceFormatterRegistry- Overrides:
addParserin classFormattingConversionService
-
addFormatter
- Specified by:
addFormatterin interfaceFormatterRegistry- Overrides:
addFormatterin classFormattingConversionService
-
addFormatterForFieldType
- Specified by:
addFormatterForFieldTypein interfaceFormatterRegistry- Overrides:
addFormatterForFieldTypein classFormattingConversionService
-
addConverter
- Specified by:
addConverterin interfaceConverterRegistry- Overrides:
addConverterin classGenericConversionService
-
addFormatterForFieldType
- Specified by:
addFormatterForFieldTypein interfaceFormatterRegistry- Overrides:
addFormatterForFieldTypein classFormattingConversionService
-
addFormatterForFieldAnnotation
public void addFormatterForFieldAnnotation(AnnotationFormatterFactory<? extends Annotation> annotationFormatterFactory) - Specified by:
addFormatterForFieldAnnotationin interfaceFormatterRegistry- Overrides:
addFormatterForFieldAnnotationin classFormattingConversionService
-
addConverter
public <S,T> void addConverter(Class<S> sourceType, Class<T> targetType, Converter<? super S, ? extends T> converter) - Specified by:
addConverterin interfaceConverterRegistry- Overrides:
addConverterin classGenericConversionService
-
addConverter
- Specified by:
addConverterin interfaceConverterRegistry- Overrides:
addConverterin classGenericConversionService
-
addConverterFactory
- Specified by:
addConverterFactoryin interfaceConverterRegistry- Overrides:
addConverterFactoryin classGenericConversionService
-
removeConvertible
- Specified by:
removeConvertiblein interfaceConverterRegistry- Overrides:
removeConvertiblein classGenericConversionService
-
isConvertViaObjectSourceType
Returntrueif objects ofsourceTypecan be converted to thetargetTypeand the converter hasObject.classas a supported source type.- Parameters:
sourceType- the source type to testtargetType- the target type to test- Returns:
- if conversion happens through an
ObjectTo...converter - Since:
- 2.4.3
-
configure
Configure the givenFormatterRegistrywith 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
AddPrinter,Parser,Formatter,Converter,ConverterFactory,GenericConverter, and beans from the specified bean factory.- Parameters:
registry- the service to register beans withbeanFactory- the bean factory to get the beans from- Since:
- 2.2.0
-
addBeans
public static Map<String,Object> addBeans(FormatterRegistry registry, ListableBeanFactory beanFactory, @Nullable String qualifier) AddPrinter,Parser,Formatter,Converter,ConverterFactory,GenericConverter, and beans from the specified bean factory.- Parameters:
registry- the service to register beans withbeanFactory- the bean factory to get the beans fromqualifier- the qualifier required on the beans ornull- Returns:
- the beans that were added
- Since:
- 3.5.0
-