Package org.beanio.types
Class StringTypeHandler
- java.lang.Object
-
- org.beanio.types.StringTypeHandler
-
- All Implemented Interfaces:
TypeHandler
public class StringTypeHandler extends java.lang.Object implements TypeHandler
A type handler implementation for theString
class.- Since:
- 1.0
-
-
Field Summary
-
Fields inherited from interface org.beanio.types.TypeHandler
NIL
-
-
Constructor Summary
Constructors Constructor Description StringTypeHandler()
-
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 callingObject.toString()
.java.lang.Class<?>
getType()
Returns the class type supported by this handler.boolean
isNullIfEmpty()
Returnstrue
if empty string values are parsed asnull
.boolean
isTrim()
Returnstrue
ifparse(String)
should trim the text.java.lang.String
parse(java.lang.String text)
Parses aString
from the given text.void
setNullIfEmpty(boolean nullIfEmpty)
Set totrue
if the parsed empty strings should be converted tonull
.void
setTrim(boolean trim)
Set totrue
to trim text when parsing.
-
-
-
Method Detail
-
parse
public java.lang.String parse(java.lang.String text)
Parses aString
from the given text.- Specified by:
parse
in interfaceTypeHandler
- Parameters:
text
- the text to parse- Returns:
- the parsed
String
-
format
public java.lang.String format(java.lang.Object value)
Formats the value by callingObject.toString()
.- Specified by:
format
in interfaceTypeHandler
- Parameters:
value
- the value to format- Returns:
- the formatted value, or
null
ifvalue
isnull
-
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 interfaceTypeHandler
- Returns:
- the class type supported by this handler
-
isTrim
public boolean isTrim()
Returnstrue
ifparse(String)
should trim the text. By default,trim
isfalse
which allows trimming to be controlled by the field definition.- Returns:
true
if parsed text is trimmed
-
setTrim
public void setTrim(boolean trim)
Set totrue
to trim text when parsing.- Parameters:
trim
-true
if text should be trimmed when parsed
-
isNullIfEmpty
public boolean isNullIfEmpty()
Returnstrue
if empty string values are parsed asnull
. Defaults tofalse
.- Returns:
true
to convert the empty string tonull
-
setNullIfEmpty
public void setNullIfEmpty(boolean nullIfEmpty)
Set totrue
if the parsed empty strings should be converted tonull
.- Parameters:
nullIfEmpty
-true
to convert empty string tonull
-
-