0

I'm developing web services using Fuse 6.2.1 (Switchyard, Apache Camel) and Maven, and I'm having a problem with fields with the type which I want them to handle values up to a precision of 23 and a scale of 2. Whenever I have a value with a precision over 7, then the format changes to Scientific Notation. Since I'm working in a Bank, this is a mayor issue

An example field on my XSD for my service is as follows:

<xs:element minOccurs="1" name="amount" type="xs:decimal" />

Later I switched the declaration to this:

    <xs:element minOccurs="1" name="amount" >
        <xs:simpleType>
            <xs:restriction base="xs:decimal">
                <xs:fractionDigits value="2" />
                <xs:totalDigits value="23"/>
                <xs:pattern value="[0-9][.][0-9]"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:element>

But the scientific notation, stays the same way. In my java code I'm printing the variable and the format is correct, and more important, my service has 2 routes inside the camel, one for SOAP, and one for REST (JSON) and the JSON response is the one with the problem, SOAP works great, so I'm guessing the problem is creating the Json response but I'm not sure how to handle this

In my many test, I have a Table with this field value "1234567890123456789.00" and on SOAP I get: 1234567890123456789.00 but on Json: "amount": 1.23456789012345677E18

Please if anyone knows how to solve this

Luis Santana
  • 1
  • 1
  • 4

2 Answers2

0

I don't have the time to write a proper answer, but this must be an issue with the serialization of your JSON. Your value must be read from your SOAP to a BigDecimal and then to a String into your JSON which must be using the toString() function which will use scientific notation for big numbers.

So to fix your Json: If you build a custom JSON serializer that specify how to serialize BigDecimals, you want to use the BigDecimal.toPlainString() in there (of course making sure you set the scale. I would avoid using the MathContext since the way MathContext is not super intuitive).

ChaudPain
  • 216
  • 1
  • 11
  • Thanks for answering. I'm searching how to create a custom JSON serializer. The structure of this service was already established when I started working here, and never before did I worked constructing JSON files and, to be honest, I'm not sure how this service (or any other) does it – Luis Santana Feb 19 '18 at 19:49
0

We resolved this issue using only string for those fields with really large numbers. The application consuming these only need to show those numbers and not making any type of calculation, so it was a compromise to do it like that, and since we didn't had too much time, the only viable solution was that

Luis Santana
  • 1
  • 1
  • 4