View Javadoc
1   /*
2    * CSVeed (https://github.com/42BV/CSVeed)
3    *
4    * Copyright 2013-2023 CSVeed.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of The Apache Software License,
8    * Version 2.0 which accompanies this distribution, and is available at
9    * https://www.apache.org/licenses/LICENSE-2.0.txt
10   */
11  package org.csveed.annotations;
12  
13  import java.lang.annotation.ElementType;
14  import java.lang.annotation.Retention;
15  import java.lang.annotation.RetentionPolicy;
16  import java.lang.annotation.Target;
17  
18  /**
19   * Various settings for a BeanInstructionsImpl translating to a CSV cell. By default every field in a
20   * BeanInstructionsImpl is expected to be a CsvCell, even if not so marked. Use @CsvIgnore to prevent a
21   * BeanInstructionsImpl field from being taken into account for both serialization and deserialization.
22   */
23  @Target(ElementType.FIELD)
24  @Retention(RetentionPolicy.RUNTIME)
25  public @interface CsvCell {
26  
27      /**
28       * This value will only be used if CsvFile.useHeaders == false. If this value is not set, the index will be
29       * automatically determined on the basis of the order of the fields within the class. If this value is set, the
30       * column at the index position will be used for mapping to this field. A 1-based approach is used because the error
31       * report is aimed at the Excel user, not the developer.
32       *
33       * @return the index column to use for the mapping
34       */
35      int columnIndex() default -1;
36  
37      /**
38       * By default the column name is inferred from the property name. However, if CsvFile.useHeaders == false, or the
39       * naming is not what you want in the BeanInstructions, you can override the column name to map to using this value.
40       *
41       * @return the column name in the CSV file header to use for mapping
42       */
43      String columnName() default "";
44  
45      /**
46       * If required is set, the parse process will generate an error if the value is null after deserialization.
47       *
48       * @return whether the field must be not null
49       */
50      boolean required() default false;
51  
52  }