Package com.opencsv.bean.processor
Class ConvertEmptyOrBlankStringsToDefault
- java.lang.Object
-
- com.opencsv.bean.processor.ConvertEmptyOrBlankStringsToDefault
-
- All Implemented Interfaces:
StringProcessor
public class ConvertEmptyOrBlankStringsToDefault extends java.lang.Object implements StringProcessor
StringProcessor that converts the empty or blank strings to a desired value string. This is useful when you want a default value.A sample of this can be found in the unit test ProcessorTestBean and is annotated as follows.
@PreAssignmentProcessor(processor = ConvertEmptyOrBlankStringsToDefault.class, paramString = "-1") @CsvBindByName(column = "id") private int beanId;- Since:
- 5.4
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.StringdefaultValue
-
Constructor Summary
Constructors Constructor Description ConvertEmptyOrBlankStringsToDefault()Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringprocessString(java.lang.String value)Method that contains the code that will transform a string into the value that will be validated and converted into the bean field.voidsetParameterString(java.lang.String value)This allows the validator extendingStringProcessorto be used by multiple fields by allowing you to pass in data for the processor to be used.
-
-
-
Method Detail
-
processString
public java.lang.String processString(java.lang.String value)
Description copied from interface:StringProcessorMethod that contains the code that will transform a string into the value that will be validated and converted into the bean field.- Specified by:
processStringin interfaceStringProcessor- Parameters:
value-Stringto be processed- Returns:
- The processed
String
-
setParameterString
public void setParameterString(java.lang.String value)
Description copied from interface:StringProcessorThis allows the validator extendingStringProcessorto be used by multiple fields by allowing you to pass in data for the processor to be used.The data could be a default value or whatever the custom processor requires to convert the data.
If the processor needs multiple parameters, then you will need to combine them into a single string using some sort of delimiter, say a comma, and parse them out using some library that allows you to parse such strings 😁.
If the processor does not need a value then just create an empty method like the ConvertEmptyOrBlankStringsToNull processor used by the BeanFieldProcessorTest.
- Specified by:
setParameterStringin interfaceStringProcessor- Parameters:
value- Information used by the processor to process the string
-
-