Class ApplicationConversionService
java.lang.Object
org.springframework.core.convert.support.GenericConversionService
org.springframework.format.support.FormattingConversionService
org.springframework.boot.convert.ApplicationConversionService
- All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.EmbeddedValueResolverAware, org.springframework.core.convert.ConversionService, org.springframework.core.convert.converter.ConverterRegistry, org.springframework.core.convert.support.ConfigurableConversionService, org.springframework.format.FormatterRegistry
public class ApplicationConversionService
extends org.springframework.format.support.FormattingConversionService
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
-
Constructor Summary
ConstructorsConstructorDescriptionApplicationConversionService(@Nullable org.springframework.util.StringValueResolver embeddedValueResolver) -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddApplicationConverters(org.springframework.core.convert.converter.ConverterRegistry registry) Add converters useful for most Spring Boot applications.static voidaddApplicationFormatters(org.springframework.format.FormatterRegistry registry) Add formatters useful for most Spring Boot applications.static voidaddBeans(org.springframework.format.FormatterRegistry registry, org.springframework.beans.factory.ListableBeanFactory beanFactory) AddPrinter,Parser,Formatter,Converter,ConverterFactory,GenericConverter, and beans from the specified bean factory.addBeans(org.springframework.format.FormatterRegistry registry, org.springframework.beans.factory.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, org.springframework.core.convert.converter.Converter<? super S, ? extends T> converter) voidaddConverter(org.springframework.core.convert.converter.Converter<?, ?> converter) voidaddConverter(org.springframework.core.convert.converter.GenericConverter converter) voidaddConverterFactory(org.springframework.core.convert.converter.ConverterFactory<?, ?> factory) static voidaddDelimitedStringConverters(org.springframework.core.convert.converter.ConverterRegistry registry) Add converters to support delimited strings.voidaddFormatter(org.springframework.format.Formatter<?> formatter) voidaddFormatterForFieldAnnotation(org.springframework.format.AnnotationFormatterFactory<? extends Annotation> annotationFormatterFactory) voidaddFormatterForFieldType(Class<?> fieldType, org.springframework.format.Formatter<?> formatter) voidaddFormatterForFieldType(Class<?> fieldType, org.springframework.format.Printer<?> printer, org.springframework.format.Parser<?> parser) voidaddParser(org.springframework.format.Parser<?> parser) voidaddPrinter(org.springframework.format.Printer<?> printer) static voidconfigure(org.springframework.format.FormatterRegistry registry) Configure the givenFormatterRegistrywith formatters and converters appropriate for most Spring Boot applications.static org.springframework.core.convert.ConversionServiceReturn a shared default applicationConversionServiceinstance, lazily building it once needed.booleanisConvertViaObjectSourceType(org.springframework.core.convert.TypeDescriptor sourceType, org.springframework.core.convert.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 org.springframework.format.support.FormattingConversionService
setEmbeddedValueResolverMethods inherited from class org.springframework.core.convert.support.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 org.springframework.core.convert.ConversionService
convert
-
Constructor Details
-
ApplicationConversionService
public ApplicationConversionService() -
ApplicationConversionService
public ApplicationConversionService(@Nullable org.springframework.util.StringValueResolver embeddedValueResolver)
-
-
Method Details
-
addPrinter
public void addPrinter(org.springframework.format.Printer<?> printer) - Specified by:
addPrinterin interfaceorg.springframework.format.FormatterRegistry- Overrides:
addPrinterin classorg.springframework.format.support.FormattingConversionService
-
addParser
public void addParser(org.springframework.format.Parser<?> parser) - Specified by:
addParserin interfaceorg.springframework.format.FormatterRegistry- Overrides:
addParserin classorg.springframework.format.support.FormattingConversionService
-
addFormatter
public void addFormatter(org.springframework.format.Formatter<?> formatter) - Specified by:
addFormatterin interfaceorg.springframework.format.FormatterRegistry- Overrides:
addFormatterin classorg.springframework.format.support.FormattingConversionService
-
addFormatterForFieldType
public void addFormatterForFieldType(Class<?> fieldType, org.springframework.format.Formatter<?> formatter) - Specified by:
addFormatterForFieldTypein interfaceorg.springframework.format.FormatterRegistry- Overrides:
addFormatterForFieldTypein classorg.springframework.format.support.FormattingConversionService
-
addConverter
public void addConverter(org.springframework.core.convert.converter.Converter<?, ?> converter) - Specified by:
addConverterin interfaceorg.springframework.core.convert.converter.ConverterRegistry- Overrides:
addConverterin classorg.springframework.core.convert.support.GenericConversionService
-
addFormatterForFieldType
public void addFormatterForFieldType(Class<?> fieldType, org.springframework.format.Printer<?> printer, org.springframework.format.Parser<?> parser) - Specified by:
addFormatterForFieldTypein interfaceorg.springframework.format.FormatterRegistry- Overrides:
addFormatterForFieldTypein classorg.springframework.format.support.FormattingConversionService
-
addFormatterForFieldAnnotation
public void addFormatterForFieldAnnotation(org.springframework.format.AnnotationFormatterFactory<? extends Annotation> annotationFormatterFactory) - Specified by:
addFormatterForFieldAnnotationin interfaceorg.springframework.format.FormatterRegistry- Overrides:
addFormatterForFieldAnnotationin classorg.springframework.format.support.FormattingConversionService
-
addConverter
public <S,T> void addConverter(Class<S> sourceType, Class<T> targetType, org.springframework.core.convert.converter.Converter<? super S, ? extends T> converter) - Specified by:
addConverterin interfaceorg.springframework.core.convert.converter.ConverterRegistry- Overrides:
addConverterin classorg.springframework.core.convert.support.GenericConversionService
-
addConverter
public void addConverter(org.springframework.core.convert.converter.GenericConverter converter) - Specified by:
addConverterin interfaceorg.springframework.core.convert.converter.ConverterRegistry- Overrides:
addConverterin classorg.springframework.core.convert.support.GenericConversionService
-
addConverterFactory
public void addConverterFactory(org.springframework.core.convert.converter.ConverterFactory<?, ?> factory) - Specified by:
addConverterFactoryin interfaceorg.springframework.core.convert.converter.ConverterRegistry- Overrides:
addConverterFactoryin classorg.springframework.core.convert.support.GenericConversionService
-
removeConvertible
-
isConvertViaObjectSourceType
public boolean isConvertViaObjectSourceType(org.springframework.core.convert.TypeDescriptor sourceType, org.springframework.core.convert.TypeDescriptor targetType) 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
public static void configure(org.springframework.format.FormatterRegistry registry) 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
public static void addApplicationConverters(org.springframework.core.convert.converter.ConverterRegistry registry) 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
public static void addDelimitedStringConverters(org.springframework.core.convert.converter.ConverterRegistry registry) 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
public static void addApplicationFormatters(org.springframework.format.FormatterRegistry registry) Add formatters useful for most Spring Boot applications.- Parameters:
registry- the service to register default formatters with
-
addBeans
public static void addBeans(org.springframework.format.FormatterRegistry registry, org.springframework.beans.factory.ListableBeanFactory beanFactory) 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(org.springframework.format.FormatterRegistry registry, org.springframework.beans.factory.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
-