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 theStringclass.- 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.Stringformat(java.lang.Object value)Formats the value by callingObject.toString().java.lang.Class<?>getType()Returns the class type supported by this handler.booleanisNullIfEmpty()Returnstrueif empty string values are parsed asnull.booleanisTrim()Returnstrueifparse(String)should trim the text.java.lang.Stringparse(java.lang.String text)Parses aStringfrom the given text.voidsetNullIfEmpty(boolean nullIfEmpty)Set totrueif the parsed empty strings should be converted tonull.voidsetTrim(boolean trim)Set totrueto trim text when parsing.
-
-
-
Method Detail
-
parse
public java.lang.String parse(java.lang.String text)
Parses aStringfrom the given text.- Specified by:
parsein 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:
formatin interfaceTypeHandler- Parameters:
value- the value to format- Returns:
- the formatted value, or
nullifvalueisnull
-
getType
public java.lang.Class<?> getType()
Description copied from interface:TypeHandlerReturns the class type supported by this handler. Primitive types should not be returned by this method- use the object equivalent instead.- Specified by:
getTypein interfaceTypeHandler- Returns:
- the class type supported by this handler
-
isTrim
public boolean isTrim()
Returnstrueifparse(String)should trim the text. By default,trimisfalsewhich allows trimming to be controlled by the field definition.- Returns:
trueif parsed text is trimmed
-
setTrim
public void setTrim(boolean trim)
Set totrueto trim text when parsing.- Parameters:
trim-trueif text should be trimmed when parsed
-
isNullIfEmpty
public boolean isNullIfEmpty()
Returnstrueif empty string values are parsed asnull. Defaults tofalse.- Returns:
trueto convert the empty string tonull
-
setNullIfEmpty
public void setNullIfEmpty(boolean nullIfEmpty)
Set totrueif the parsed empty strings should be converted tonull.- Parameters:
nullIfEmpty-trueto convert empty string tonull
-
-