This is something similar to what I have:
@CsvRecord(separator = "\\t", skipFirstLine = true)
public class Inventory {
@DataField(pos = 1, required=false)
private String vendor;
@DataField(pos = 2, required=false)
private String sku;
@DataField(pos = 3, required=false)
private Integer stock;
}
If any column 2 or 3 are empty, there is no issue at all, those fields just have a null value (imagine that -> is a tab representation).
VENDOR->SKU->STOCK
Vendor1->123->5
Vendor1->->10
With a binding result like
[{
vendor: "Vendor1",
sku: "123",
stock: 5
},
{
vendor: "Vendor1",
sku: null,
stock: 10
}]
So far, so good, but when the first column is null, the column 2 value (sku) is assigned by the binder to the column 1 binded attribute "vendor", and the column 3 value is assinged to the column 2 binded attribute (sku), and the the actual attribute binded to column 3 stays null:
VENDOR->SKU->STOCK
null->123->5
Vendor1->166->10
Does something like this:
[{
vendor: "123",
sku: "5",
stock: null
},
{
vendor: "Vendor1",
sku: "166",
stock: 10
}]
I know I can always make it "required=true" (that's how it was done in the first place), but still it doesn't fail if the second one is not null, since that one is assigned to the first one; and, in the other hand, doing columns required true, in our case is not a good idea, because because one row is missing something, the whole file is rejected, so our strategy is to validate those fields that are mandatory for us manually so we can log it right and process whatever rows are corrects in all columns.
This is my dependency of this library:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-bindy</artifactId>
<version>2.11.1</version>
</dependency>
And this would be the name of the binding library:
camel-bindy-2.11.1.jar
I checked all attributes I have in the CsvRecord annotation as well as in the DataField annotation, tried blindly with some of them with the hope that will solve it.
Does anyone know why could this be happening? or if it is a library issue solved in later version? or any suggestion I can try?
Of course, I'm grateful in advance for any help or answer I can get!