Top Description Fields Constructors Methods
com.opencsv.bean.processor

public Class ConvertEmptyOrBlankStringsToDefault

extends Object
implements StringProcessor
Class Inheritance
All Implemented Interfaces
com.opencsv.bean.processor.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;
Author
Scott Conway
Since
5.4

Field Summary

Modifier and TypeField and Description
pack-priv String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
processString(String value)

Implements com.opencsv.bean.processor.StringProcessor.processString.

Method that contains the code that will transform a string into the value that will be validated and converted into the bean field.

public void
setParameterString(String value)

Implements com.opencsv.bean.processor.StringProcessor.setParameterString.

This allows the validator extending StringProcessor to be used by multiple fields by allowing you to pass in data for the processor to be used.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultValueback to summary
pack-priv String defaultValue

Constructor Detail

ConvertEmptyOrBlankStringsToDefaultback to summary
public ConvertEmptyOrBlankStringsToDefault()

Default constructor

Method Detail

processStringback to summary
public String processString(String value)

Implements com.opencsv.bean.processor.StringProcessor.processString.

Doc from com.opencsv.bean.processor.StringProcessor.processString.

Method that contains the code that will transform a string into the value that will be validated and converted into the bean field.

Annotations
@Override
setParameterStringback to summary
public void setParameterString(String value)

Implements com.opencsv.bean.processor.StringProcessor.setParameterString.

Doc from com.opencsv.bean.processor.StringProcessor.setParameterString.

This allows the validator extending StringProcessor 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.

Annotations
@Override