Class StringTypeHandler

  • All Implemented Interfaces:
    TypeHandler

    public class StringTypeHandler
    extends java.lang.Object
    implements TypeHandler
    A type handler implementation for the String class.
    Since:
    1.0
    • Field Summary

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String format​(java.lang.Object value)
      Formats the value by calling Object.toString().
      java.lang.Class<?> getType()
      Returns the class type supported by this handler.
      boolean isNullIfEmpty()
      Returns true if empty string values are parsed as null.
      boolean isTrim()
      Returns true if parse(String) should trim the text.
      java.lang.String parse​(java.lang.String text)
      Parses a String from the given text.
      void setNullIfEmpty​(boolean nullIfEmpty)
      Set to true if the parsed empty strings should be converted to null.
      void setTrim​(boolean trim)
      Set to true to trim text when parsing.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StringTypeHandler

        public StringTypeHandler()
    • Method Detail

      • parse

        public java.lang.String parse​(java.lang.String text)
        Parses a String from the given text.
        Specified by:
        parse in interface TypeHandler
        Parameters:
        text - the text to parse
        Returns:
        the parsed String
      • format

        public java.lang.String format​(java.lang.Object value)
        Formats the value by calling Object.toString().
        Specified by:
        format in interface TypeHandler
        Parameters:
        value - the value to format
        Returns:
        the formatted value, or null if value is null
      • getType

        public java.lang.Class<?> getType()
        Description copied from interface: TypeHandler
        Returns the class type supported by this handler. Primitive types should not be returned by this method- use the object equivalent instead.
        Specified by:
        getType in interface TypeHandler
        Returns:
        the class type supported by this handler
      • isTrim

        public boolean isTrim()
        Returns true if parse(String) should trim the text. By default, trim is false which allows trimming to be controlled by the field definition.
        Returns:
        true if parsed text is trimmed
      • setTrim

        public void setTrim​(boolean trim)
        Set to true to trim text when parsing.
        Parameters:
        trim - true if text should be trimmed when parsed
      • isNullIfEmpty

        public boolean isNullIfEmpty()
        Returns true if empty string values are parsed as null. Defaults to false.
        Returns:
        true to convert the empty string to null
      • setNullIfEmpty

        public void setNullIfEmpty​(boolean nullIfEmpty)
        Set to true if the parsed empty strings should be converted to null.
        Parameters:
        nullIfEmpty - true to convert empty string to null