You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by lb <lb...@gmail.com> on 2012/11/20 12:54:04 UTC

[camel-bindy] Handle implied decimal field

Hy all,
is tenere any way to handle numbers represented with implied decimals?


I mean, the communication with some legacy systems often relies on old
protocols and formats not easy to change and among that you may have to deal
with fixed lenght records on which decimal numbers are not represented with
a decimal separator but the number of decimal places is defined by the
protocol definition (e.g. COBOL copy-book).

Example:

@DataField(pos = 7, length = 5, precision = 2, sign = true,
implied-decimal-separator = true)
private BigDecimal amount;

The string "-1234" maps to -12.34 in Java.


If a solution does not exists I may start to work on it, if there is a
little interest of course.

Thx







--
View this message in context: http://camel.465427.n5.nabble.com/camel-bindy-Handle-implied-decimal-field-tp5723003.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: [camel-bindy] Handle implied decimal field

Posted by lb <lb...@gmail.com>.
Patch for both implied decimal and format attached to CAMEL-5827
(https://issues.apache.org/jira/browse/CAMEL-5827). 
Still lot of work to do but as it is my first patch to an Apache project, I
would like to know if it goes the right way :-)




--
View this message in context: http://camel.465427.n5.nabble.com/camel-bindy-Handle-implied-decimal-field-tp5723003p5723343.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: [camel-bindy] Handle implied decimal field

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Nov 27, 2012 at 9:00 AM, lb <lb...@gmail.com> wrote:
>
> In org.apache.camel.dataformat.bindy.FormatFactory for non "BigNumbers" the
> Format object is chosen as follow:
>
> if (clazz == float.class || clazz == Float.class) {
>     return pattern != null ? new FloatPatternFormat(pattern,
> getLocale(locale)) : new FloatFormat();
> }
>
> I've noticed that the DataFiled annotation define the pattern field with ""
> (empty String) as default value, thus the FormatFactory will always return
> the *PatternFormat and never the simple *Format.
>
> Is there a reason for such behavior?
>

I would assume even an "" pattern would cause the FloatPatternFormat
to fail. So the code is "correct" although it seems broken.
What may be better is to use ObjectHelper.isEmpty(pattern) which
checks for null/empty strings.

Feel free to open a JIRA and submit a patch.
We love contributions
http://camel.apache.org/contributing.html

>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-bindy-Handle-implied-decimal-field-tp5723003p5723280.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: [camel-bindy] Handle implied decimal field

Posted by lb <lb...@gmail.com>.
In org.apache.camel.dataformat.bindy.FormatFactory for non "BigNumbers" the
Format object is chosen as follow:  

if (clazz == float.class || clazz == Float.class) {
    return pattern != null ? new FloatPatternFormat(pattern,
getLocale(locale)) : new FloatFormat();
}

I've noticed that the DataFiled annotation define the pattern field with ""
(empty String) as default value, thus the FormatFactory will always return
the *PatternFormat and never the simple *Format. 

Is there a reason for such behavior?






--
View this message in context: http://camel.465427.n5.nabble.com/camel-bindy-Handle-implied-decimal-field-tp5723003p5723280.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: [camel-bindy] Handle implied decimal field

Posted by santoshjoshi <sa...@gmail.com>.
Hi All,

I have created some examples for Camel Bindy.
these all have been checked in at:

https://github.com/santoshjoshi/camel-bindy-example
<https://github.com/santoshjoshi/camel-bindy-example>  



Regards
Santosh Joshi




--
View this message in context: http://camel.465427.n5.nabble.com/camel-bindy-Handle-implied-decimal-field-tp5723003p5723065.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: [camel-bindy] Handle implied decimal field

Posted by Christian Müller <ch...@gmail.com>.
I think the source code of camel-bindy and its unit tests [1] is a good
starting point.
And you should be also familiar with how to build Camel [2] and how to
contribute [3].

[1] https://svn.apache.org/repos/asf/camel/trunk/components/camel-bindy/
[2] http://camel.apache.org/building.html
[3] http://camel.apache.org/contributing.html

Best,
Christian

On Tue, Nov 20, 2012 at 4:29 PM, lb <lb...@gmail.com> wrote:

>
> thx - could you point me to some relevant code for learning purpose?
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/camel-bindy-Handle-implied-decimal-field-tp5723003p5723019.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: [camel-bindy] Handle implied decimal field

Posted by lb <lb...@gmail.com>.
thx - could you point me to some relevant code for learning purpose? 



--
View this message in context: http://camel.465427.n5.nabble.com/camel-bindy-Handle-implied-decimal-field-tp5723003p5723019.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: [camel-bindy] Handle implied decimal field

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Nov 20, 2012 at 12:54 PM, lb <lb...@gmail.com> wrote:
> Hy all,
> is tenere any way to handle numbers represented with implied decimals?
>
>
> I mean, the communication with some legacy systems often relies on old
> protocols and formats not easy to change and among that you may have to deal
> with fixed lenght records on which decimal numbers are not represented with
> a decimal separator but the number of decimal places is defined by the
> protocol definition (e.g. COBOL copy-book).
>
> Example:
>
> @DataField(pos = 7, length = 5, precision = 2, sign = true,
> implied-decimal-separator = true)
> private BigDecimal amount;
>
> The string "-1234" maps to -12.34 in Java.
>
>
> If a solution does not exists I may start to work on it, if there is a
> little interest of course.
>

This is currently not support. We love contributions
http://camel.apache.org/contributing.html



> Thx
>
>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-bindy-Handle-implied-decimal-field-tp5723003.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen