play.data.format
Class Formatters

java.lang.Object
  extended by play.data.format.Formatters

public class Formatters
extends java.lang.Object

Formatters helper.


Nested Class Summary
static class Formatters.AnnotationFormatter<A extends java.lang.annotation.Annotation,T>
          Super-type for annotation-based formatters.
static class Formatters.SimpleFormatter<T>
          Super-type for custom simple formatters.
 
Field Summary
static org.springframework.format.support.FormattingConversionService conversion
          The underlying conversion service.
 
Constructor Summary
Formatters()
           
 
Method Summary
static
<T> T
parse(java.lang.reflect.Field field, java.lang.String text, java.lang.Class<T> clazz)
          Parses this string as instance of a specific field in the given class
static
<T> T
parse(java.lang.String text, java.lang.Class<T> clazz)
          Parses this string as instance of the given class.
static
<T> java.lang.String
print(java.lang.reflect.Field field, T t)
          Computes the display string for any value, for a specific field.
static
<T> java.lang.String
print(T t)
          Computes the display string for any value.
static
<T> java.lang.String
print(org.springframework.core.convert.TypeDescriptor desc, T t)
          Computes the display string for any value, for a specific type.
static
<A extends java.lang.annotation.Annotation,T>
void
register(java.lang.Class<T> clazz, Formatters.AnnotationFormatter<A,T> formatter)
          Registers an annotation-based formatter.
static
<T> void
register(java.lang.Class<T> clazz, Formatters.SimpleFormatter<T> formatter)
          Registers a simple formatter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

conversion

public static final org.springframework.format.support.FormattingConversionService conversion
The underlying conversion service.

Constructor Detail

Formatters

public Formatters()
Method Detail

parse

public static <T> T parse(java.lang.String text,
                          java.lang.Class<T> clazz)
Parses this string as instance of the given class.

Parameters:
text - the text to parse
clazz - class representing the required type
Returns:
the parsed value

parse

public static <T> T parse(java.lang.reflect.Field field,
                          java.lang.String text,
                          java.lang.Class<T> clazz)
Parses this string as instance of a specific field in the given class

Parameters:
field - the related field (custom formatters are extracted from this field annotation)
text - the text to parse
clazz - class representing the required type
Returns:
the parsed value

print

public static <T> java.lang.String print(T t)
Computes the display string for any value.

Parameters:
t - the value to print
Returns:
the formatted string

print

public static <T> java.lang.String print(java.lang.reflect.Field field,
                                         T t)
Computes the display string for any value, for a specific field.

Parameters:
field - the related field - custom formatters are extracted from this field annotation
t - the value to print
Returns:
the formatted string

print

public static <T> java.lang.String print(org.springframework.core.convert.TypeDescriptor desc,
                                         T t)
Computes the display string for any value, for a specific type.

Parameters:
desc - the field descriptor - custom formatters are extracted from this descriptor.
t - the value to print
Returns:
the formatted string

register

public static <T> void register(java.lang.Class<T> clazz,
                                Formatters.SimpleFormatter<T> formatter)
Registers a simple formatter.

Parameters:
clazz - class handled by this formatter
formatter - the formatter to register

register

public static <A extends java.lang.annotation.Annotation,T> void register(java.lang.Class<T> clazz,
                                                                          Formatters.AnnotationFormatter<A,T> formatter)
Registers an annotation-based formatter.

Parameters:
clazz - class handled by this formatter
formatter - the formatter to register