Package com.opencsv.bean.processor
Class ConvertEmptyOrBlankStringsToDefault
java.lang.Object
com.opencsv.bean.processor.ConvertEmptyOrBlankStringsToDefault
- All Implemented Interfaces:
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprocessString
(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.void
setParameterString
(String value) This allows the validator extendingStringProcessor
to be used by multiple fields by allowing you to pass in data for the processor to be used.
-
Field Details
-
defaultValue
String defaultValue
-
-
Constructor Details
-
ConvertEmptyOrBlankStringsToDefault
public ConvertEmptyOrBlankStringsToDefault()Default constructor
-
-
Method Details
-
processString
Description copied from interface:StringProcessor
Method that contains the code that will transform a string into the value that will be validated and converted into the bean field.- Specified by:
processString
in interfaceStringProcessor
- Parameters:
value
-String
to be processed- Returns:
- The processed
String
-
setParameterString
Description copied from interface:StringProcessor
This allows the validator extendingStringProcessor
to 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:
setParameterString
in interfaceStringProcessor
- Parameters:
value
- Information used by the processor to process the string
-