@Singleton public class Formatters extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Formatters.AnnotationFormatter<A extends Annotation,T>
Super-type for annotation-based formatters.
|
static class |
Formatters.SimpleFormatter<T>
Super-type for custom simple formatters.
|
Modifier and Type | Field and Description |
---|---|
org.springframework.format.support.FormattingConversionService |
conversion
The underlying conversion service.
|
Constructor and Description |
---|
Formatters(MessagesApi messagesApi) |
Modifier and Type | Method and Description |
---|---|
<T> T |
parse(Field field,
String text)
Parses this string as instance of a specific field
|
<T> T |
parse(String text,
Class<T> clazz)
Parses this string as instance of the given class.
|
<T> String |
print(Field field,
T t)
Computes the display string for any value, for a specific field.
|
<T> String |
print(T t)
Computes the display string for any value.
|
<T> String |
print(org.springframework.core.convert.TypeDescriptor desc,
T t)
Computes the display string for any value, for a specific type.
|
<A extends Annotation,T> |
register(Class<T> clazz,
Formatters.AnnotationFormatter<A,T> formatter)
Registers an annotation-based formatter.
|
<T> Formatters |
register(Class<T> clazz,
Formatters.SimpleFormatter<T> formatter)
Registers a simple formatter.
|
public final org.springframework.format.support.FormattingConversionService conversion
@Inject public Formatters(MessagesApi messagesApi)
public <T> T parse(String text, Class<T> clazz)
T
- the type to parse out of the texttext
- the text to parseclazz
- class representing the required typepublic <T> T parse(Field field, String text)
T
- the type to parse out of the textfield
- the related field (custom formatters are extracted from this field annotation)text
- the text to parsepublic <T> String print(T t)
T
- the type to printt
- the value to printpublic <T> String print(Field field, T t)
T
- the type to printfield
- the related field - custom formatters are extracted from this field annotationt
- the value to printpublic <T> String print(org.springframework.core.convert.TypeDescriptor desc, T t)
T
- the type to printdesc
- the field descriptor - custom formatters are extracted from this descriptor.t
- the value to printpublic <T> Formatters register(Class<T> clazz, Formatters.SimpleFormatter<T> formatter)
T
- the type that this formatter will parse and printclazz
- class handled by this formatterformatter
- the formatter to registerpublic <A extends Annotation,T> Formatters register(Class<T> clazz, Formatters.AnnotationFormatter<A,T> formatter)
A
- the annotation typeT
- the type that will be parsed or printedclazz
- class handled by this formatterformatter
- the formatter to register