public class FormattingConversionService extends GenericConversionService implements FormatterRegistry, EmbeddedValueResolverAware
ConversionService
implementation
designed to be configured as a FormatterRegistry
.Modifier and Type | Class and Description |
---|---|
private static class |
FormattingConversionService.AnnotationConverterKey |
private class |
FormattingConversionService.AnnotationParserConverter |
private class |
FormattingConversionService.AnnotationPrinterConverter |
private static class |
FormattingConversionService.ParserConverter |
private static class |
FormattingConversionService.PrinterConverter |
Modifier and Type | Field and Description |
---|---|
private java.util.Map<FormattingConversionService.AnnotationConverterKey,GenericConverter> |
cachedParsers |
private java.util.Map<FormattingConversionService.AnnotationConverterKey,GenericConverter> |
cachedPrinters |
private StringValueResolver |
embeddedValueResolver |
Constructor and Description |
---|
FormattingConversionService() |
Modifier and Type | Method and Description |
---|---|
void |
addFormatter(Formatter<?> formatter)
Adds a Formatter to format fields of a specific type.
|
void |
addFormatterForFieldAnnotation(AnnotationFormatterFactory<? extends java.lang.annotation.Annotation> annotationFormatterFactory)
Adds a Formatter to format fields annotated with a specific format annotation.
|
void |
addFormatterForFieldType(java.lang.Class<?> fieldType,
Formatter<?> formatter)
Adds a Formatter to format fields of the given type.
|
void |
addFormatterForFieldType(java.lang.Class<?> fieldType,
Printer<?> printer,
Parser<?> parser)
Adds a Printer/Parser pair to format fields of a specific type.
|
(package private) static java.lang.Class<? extends java.lang.annotation.Annotation> |
getAnnotationType(AnnotationFormatterFactory<? extends java.lang.annotation.Annotation> factory) |
(package private) static java.lang.Class<?> |
getFieldType(Formatter<?> formatter) |
void |
setEmbeddedValueResolver(StringValueResolver resolver)
Set the StringValueResolver to use for resolving embedded definition values.
|
addConverter, addConverter, addConverter, addConverterFactory, canBypassConvert, canConvert, canConvert, convert, convert, convert, convertNullSource, getConverter, getDefaultConverter, removeConvertible, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addConverter, addConverter, addConverter, addConverterFactory, removeConvertible
private StringValueResolver embeddedValueResolver
private final java.util.Map<FormattingConversionService.AnnotationConverterKey,GenericConverter> cachedPrinters
private final java.util.Map<FormattingConversionService.AnnotationConverterKey,GenericConverter> cachedParsers
public void setEmbeddedValueResolver(StringValueResolver resolver)
EmbeddedValueResolverAware
setEmbeddedValueResolver
in interface EmbeddedValueResolverAware
public void addFormatter(Formatter<?> formatter)
FormatterRegistry
addFormatter
in interface FormatterRegistry
formatter
- the formatter to addFormatterRegistry.addFormatterForFieldType(Class, Formatter)
public void addFormatterForFieldType(java.lang.Class<?> fieldType, Formatter<?> formatter)
FormatterRegistry
On print, if the Formatter's type T is declared and fieldType
is not assignable to T,
a coercion to T will be attempted before delegating to formatter
to print a field value.
On parse, if the parsed object returned by formatter
is not assignable to the runtime field type,
a coercion to the field type will be attempted before returning the parsed field value.
addFormatterForFieldType
in interface FormatterRegistry
fieldType
- the field type to formatformatter
- the formatter to addpublic void addFormatterForFieldType(java.lang.Class<?> fieldType, Printer<?> printer, Parser<?> parser)
FormatterRegistry
printer
for printing
and the specified parser
for parsing.
On print, if the Printer's type T is declared and fieldType
is not assignable to T,
a coercion to T will be attempted before delegating to printer
to print a field value.
On parse, if the object returned by the Parser is not assignable to the runtime field type,
a coercion to the field type will be attempted before returning the parsed field value.
addFormatterForFieldType
in interface FormatterRegistry
fieldType
- the field type to formatprinter
- the printing part of the formatterparser
- the parsing part of the formatterpublic void addFormatterForFieldAnnotation(AnnotationFormatterFactory<? extends java.lang.annotation.Annotation> annotationFormatterFactory)
FormatterRegistry
addFormatterForFieldAnnotation
in interface FormatterRegistry
annotationFormatterFactory
- the annotation formatter factory to addstatic java.lang.Class<?> getFieldType(Formatter<?> formatter)
static java.lang.Class<? extends java.lang.annotation.Annotation> getAnnotationType(AnnotationFormatterFactory<? extends java.lang.annotation.Annotation> factory)