You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by dabby11 <ma...@gmail.com> on 2016/12/20 16:01:33 UTC

camel-bindy issue with header and missing locale

Hi,

  I'm developing a route with Camel 2.16.1 that uses Bindy to process a file
with fixed length records. The file consists of a header and many rows.
I'm unmarshalling the stream with the following data format:

BindyFixedLengthDataFormat bindy = new
BindyFixedLengthDataFormat(DocumentRow.class);
bindy.setLocale("default");

and my model classes are something like:

@FixedLengthRecord(header = DocumentHeader.class)
public class DocumentRow {

    ...
	
	@DataField(pos = 10, pattern="+000000000.00;-000000000.00", precision = 2,
length = 13, decimalSeparator = ",")
	private BigDecimal value;

    ...
}

@FixedLengthRecord
public class DocumentHeader {

    ...

	@DataField(pos = 365, pattern="+000000000000.00;-000000000000.00",
precision = 2,  length = 16, decimalSeparator = ",")
	private BigDecimal total;

    ...

}

Bindy fails to parse the DocumentHeader.total field with a
java.lang.NumberFormatException.

It seems the locale specified with bindy.setLocale("default") is not passed
to the inner headerFactory in the BindyFixedLengthDataFormat and Bindy tries
to parse the number calling BigDecimal constructor, instead of parsing it
with DecimalFormat.
Indeed, if I execute the following (ugly!) code before creating the route:

  bindy.getFactory();
			
  Field field =
BindyFixedLengthDataFormat.class.getDeclaredField("headerFactory");
  field.setAccessible(true);
  BindyFixedLengthFactory headerFactory =
(BindyFixedLengthFactory)field.get(bindy);
			
  headerFactory.setLocale(bindy.getLocale());

to force the locale, everything's fine.

So I think that in BindyFixedLengthDataFormat.createModelFactory() after
headerFactory creation there should be a call to

    headerFactory.setLocale(getLocale())

or something like that (and a similar line for footerFactory).

I checked 2.17.x and 2.18.x branches of BindyFixedLengthDataFormat.java and
there's not something like this.

So the question is: is this really an issue with Bindy or should I achieve
this result in a different way ?

Regards,
  Marco



--
View this message in context: http://camel.465427.n5.nabble.com/camel-bindy-issue-with-header-and-missing-locale-tp5791746.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-bindy issue with header and missing locale

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yeah sounds like an issue, you are welcome to log a JIRA and provide a
patch or better github PR
http://camel.apache.org/contributing

On Tue, Dec 20, 2016 at 5:01 PM, dabby11 <ma...@gmail.com> wrote:
> Hi,
>
>   I'm developing a route with Camel 2.16.1 that uses Bindy to process a file
> with fixed length records. The file consists of a header and many rows.
> I'm unmarshalling the stream with the following data format:
>
> BindyFixedLengthDataFormat bindy = new
> BindyFixedLengthDataFormat(DocumentRow.class);
> bindy.setLocale("default");
>
> and my model classes are something like:
>
> @FixedLengthRecord(header = DocumentHeader.class)
> public class DocumentRow {
>
>     ...
>
>         @DataField(pos = 10, pattern="+000000000.00;-000000000.00", precision = 2,
> length = 13, decimalSeparator = ",")
>         private BigDecimal value;
>
>     ...
> }
>
> @FixedLengthRecord
> public class DocumentHeader {
>
>     ...
>
>         @DataField(pos = 365, pattern="+000000000000.00;-000000000000.00",
> precision = 2,  length = 16, decimalSeparator = ",")
>         private BigDecimal total;
>
>     ...
>
> }
>
> Bindy fails to parse the DocumentHeader.total field with a
> java.lang.NumberFormatException.
>
> It seems the locale specified with bindy.setLocale("default") is not passed
> to the inner headerFactory in the BindyFixedLengthDataFormat and Bindy tries
> to parse the number calling BigDecimal constructor, instead of parsing it
> with DecimalFormat.
> Indeed, if I execute the following (ugly!) code before creating the route:
>
>   bindy.getFactory();
>
>   Field field =
> BindyFixedLengthDataFormat.class.getDeclaredField("headerFactory");
>   field.setAccessible(true);
>   BindyFixedLengthFactory headerFactory =
> (BindyFixedLengthFactory)field.get(bindy);
>
>   headerFactory.setLocale(bindy.getLocale());
>
> to force the locale, everything's fine.
>
> So I think that in BindyFixedLengthDataFormat.createModelFactory() after
> headerFactory creation there should be a call to
>
>     headerFactory.setLocale(getLocale())
>
> or something like that (and a similar line for footerFactory).
>
> I checked 2.17.x and 2.18.x branches of BindyFixedLengthDataFormat.java and
> there's not something like this.
>
> So the question is: is this really an issue with Bindy or should I achieve
> this result in a different way ?
>
> Regards,
>   Marco
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-bindy-issue-with-header-and-missing-locale-tp5791746.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2