Search code examples
apache-camelbindy

Bindy paddingChar


In my Bindy model I would like to set a paddingChar on one field. I saw in the documentation that with a @Fixed-length record I can add a paddingChar attribute but with a @CsvRecord it seems not to be the possible ?

This code doesn't pad field mandant with "0":

@CsvRecord(separator = ";", generateHeaderColumns=true)
public class Unity{

@DataField(pos = 1, length = 3, paddingChar = '0')  String mandant;
...

Solution

  • According to the Camel documentation, you could use the pattern attribute for Double, Integer, Float, Short, Long, and BigDecimal fields. The format is defined according to java.text.DecimalFormat:

    @DataField(pos = 1, pattern = "000")
    Float mandant;
    

    EDIT:

    pattern is ignored (at least for Camel 2.13.1), if the locale is not set (a kind of a bug or at least an undocumented feature...). Thus, do the following:

    final BindyCsvDataFormat bindy = new BindyCsvDataFormat(Unity.class);
    bindy.setLocale(Locale.US.getISO3Country());
    

    EDIT:

    I opened a Jira issue as I think this should be fixed: CAMEL-7578

    EDIT:

    CAMEL-7578 is fixed for Camel versions 2.12.5, 2.13.3, and 2.14.0.