Class Formatters


  • @Singleton
    public class Formatters
    extends Object
    Formatters helper.
    • Field Detail

      • conversion

        public final org.springframework.format.support.FormattingConversionService conversion
        The underlying conversion service.
    • Constructor Detail

      • Formatters

        @Inject
        public Formatters​(MessagesApi messagesApi)
    • Method Detail

      • parse

        public <T> T parse​(String text,
                           Class<T> clazz)
        Parses this string as instance of the given class.
        Type Parameters:
        T - the type to parse out of the text
        Parameters:
        text - the text to parse
        clazz - class representing the required type
        Returns:
        the parsed value
      • parse

        public <T> T parse​(Field field,
                           String text)
        Parses this string as instance of a specific field
        Type Parameters:
        T - the type to parse out of the text
        Parameters:
        field - the related field (custom formatters are extracted from this field annotation)
        text - the text to parse
        Returns:
        the parsed value
      • print

        public <T> String print​(T t)
        Computes the display string for any value.
        Type Parameters:
        T - the type to print
        Parameters:
        t - the value to print
        Returns:
        the formatted string
      • print

        public <T> String print​(Field field,
                                T t)
        Computes the display string for any value, for a specific field.
        Type Parameters:
        T - the type to print
        Parameters:
        field - the related field - custom formatters are extracted from this field annotation
        t - the value to print
        Returns:
        the formatted string
      • print

        public <T> String print​(org.springframework.core.convert.TypeDescriptor desc,
                                T t)
        Computes the display string for any value, for a specific type.
        Type Parameters:
        T - the type to print
        Parameters:
        desc - the field descriptor - custom formatters are extracted from this descriptor.
        t - the value to print
        Returns:
        the formatted string
      • register

        public <T> Formatters register​(Class<T> clazz,
                                       Formatters.SimpleFormatter<T> formatter)
        Registers a simple formatter.
        Type Parameters:
        T - the type that this formatter will parse and print
        Parameters:
        clazz - class handled by this formatter
        formatter - the formatter to register
        Returns:
        the modified Formatters object.
      • register

        public <A extends Annotation,​T> Formatters register​(Class<T> clazz,
                                                                  Formatters.AnnotationFormatter<A,​T> formatter)
        Registers an annotation-based formatter.
        Type Parameters:
        A - the annotation type
        T - the type that will be parsed or printed
        Parameters:
        clazz - class handled by this formatter
        formatter - the formatter to register
        Returns:
        the modified Formatters object.