Class NullStringConversion
java.lang.Object
com.univocity.parsers.conversions.NullStringConversion
- All Implemented Interfaces:
Conversion<Object,
Object>
Converts Strings to null and vice versa
This class supports multiple representations of null values. For example, you can define conversions from different Strings such as "N/A, ?, -" to null.
The reverse conversion from a null to String (in revert(Object)
will return the first String provided in this class constructor if the object is null.
Using the previous example, a call to revert(Object)
will produce "N/A".
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionNullStringConversion
(String... nullRepresentations) Creates conversions from Strings to null. -
Method Summary
-
Field Details
-
nullStrings
-
defaultNullString
-
-
Constructor Details
-
NullStringConversion
Creates conversions from Strings to null.The list of Strings that identify nulls are mandatory.
- Parameters:
nullRepresentations
- Strings that identify a true value. The first element will be returned when executingrevert(Object)
-
-
Method Details
-
execute
Converts an Object to null. The string representation of the object will be used to match the string elements provided in the constructor.- Specified by:
execute
in interfaceConversion<Object,
Object> - Parameters:
input
- an Object to be converted to null.- Returns:
- null if the string representation of the object matches any one of the Strings provided in the constructor of this class. Otherwise, the original object will be returned.
-
revert
Converts a null input to a String representation. The String returned will be the first element provided in the constructor of this class.- Specified by:
revert
in interfaceConversion<Object,
Object> - Parameters:
input
- an Object that, if null, will be transformed to a String.- Returns:
- If the input is null, the string representation for null objects. Otherwise, the original object will be returned.
-