...
Parameter name | type | Info |
---|---|---|
separator | string | mandatory - can be ',' or ';' or 'anything' |
skipFirstLine | boolean | optional - default value = false - allow to skip the first line of the CSV file |
|
| This annotation is associated to the root class of the model and must be declared one time. |
case 1 : separator = ','
If the record represents orders, then this annotation is added to the Order class like this :
Code Block |
---|
@CsvRecord( separator = "," ) public Class Order { ... } |
...
Parameter name | type | Info |
---|---|---|
linkType | LinkType | optional - by default the value is LinkType.oneToOne |
|
| Only one-to-one relation is allowed. |
|
| e.g : If the model Class Client is linked to the Order class, then use annotation Link in the Order class like this: |
...
Code Block |
---|
@CsvRecord(separator = ",")
public class Order {
@DataField(pos = 0)
private int orderNr;
@Link
private Client client;
...
|
DataField
The DataField annotation defines the property of the field. Each datafield is identifed identified by its position in the record, a type (string, int, date, ...) and optionaly of a pattern
...
Parameter name | type | Info |
---|---|---|
int | pos | mandatory - digit number |
pattern | string | optional - default value = "" - will be used to format Decimal, Date, ... |
length | int | optional - digit number - represents the length of the field for fixed length format |
precision | int | optional - digit number - represents the precision to be used when the Decimal number will be formatted/parsed |
case 1 : position
Code Block |
---|
@CsvRecord(separator = ",") public class Order { @DataField(pos = 0) |
...
private int orderNr |
...
; @Link private Client client; -- class to link @DataField(pos = |
...
4)
private String isinCode;
...
}
|
case 2 : pattern
Code Block |
---|
@CsvRecord(separator = ",") public class Order { @DataField(pos = 0) private int orderNr; @Link private Client client; @DataField(pos = 4) private String isinCode; @DataField(name = "Name", pos = 5) private String instrumentName; @DataField(pos = 6, precision = 2) private BigDecimal amount; @DataField(pos = 7) private String currency; @DataField(pos = 8, pattern = "dd-MM-yyyy") |
...
-- pattern
private Date orderDate;
...
}
|
case 3 : precision
Code Block |
---|
@CsvRecord(separator = ",") public class Order { @DataField(pos = 0) private int orderNr; @Link private Client client; @DataField(pos = 4) private String isinCode; @DataField(name = "Name", pos = 5) private String instrumentName; @DataField(pos = 6, precision = 2) |
...
-- precision
private BigDecimal amount;
@DataField(pos = 7)
private String currency;
@DataField(pos = 8, pattern = "dd-MM-yyyy")
private Date orderDate;
...
}
|
Using the Java DSL
The next step consists in instantiaing the DataFormat bindy class associated with this record type and providing Java package name(s) as parameter.
...