View Javadoc
1   package com.opencsv.bean.processor;
2   
3   /**
4    * StringProcessor that converts the string value "null" to a literal null string.
5    * This is useful when you are dealing with csv files that actually use the word null.
6    * <p>
7    * A sample of this can be found in the Integration tests FR138MockBean and is annotated as follows.
8    * <p>
9    * <pre>
10   *     &#64;PreAssignmentProcessor(processor = ConvertWordNullToNull.class)
11   *     private int num;
12   * </pre>
13   * Without the annotation an CSVMalformedException is thrown when trying to conver the string "null" to an int.
14   * But with it is considered a null String and the int gets a default value of 0.
15   *
16   * @author Scott Conway
17   * @since 5.4
18   */
19  public class ConvertWordNullToNull implements StringProcessor {
20  
21      /**
22       * Default Constructor.
23       */
24      public ConvertWordNullToNull() {
25      }
26  
27      @Override
28      public String processString(String value) {
29          return "null".equalsIgnoreCase(value) ? null : value;
30      }
31  
32      /**
33       * This method is unused in this implementation as we are converting to null.
34       * Any calls to this method are ignored.
35       *
36       * @param value Information used by the processor to process the string
37       */
38      @Override
39      public void setParameterString(String value) {
40          // Unused in this case as all we care about is the word "null"
41      }
42  }