wso2esbenterpriseintegratorei

WSO2 ESB problem with convert xml to json


I use property mediator to convert xml to json <property name="messageType" scope="axis2" type="STRING" value="application/json"/>

It's work, but when the xml message contains a number like 50103015080000000550022052 then after converting to json the value changes to 5.010301508E25.

I need to have the original value. Any idea how to do this?

Thanks in advance.


Solution

  • This happens due to the auto primitive feature available with the wso2 ESB servers. Here when a conversion happens from XML JSON primitive types are automatically identified. Therefore the number 50103015080000000550022052 is identified as a number and represented in the scientific notation.

    The auto primitive feature is by default enabled in the EI server [1].

    We can disable the auto primitive feature globally by configuring synapse.commons.json.output.autoPrimitive=false in the following location. And this will be applied for all the primitive data types globally.

    [EI_HOME]/conf/synapse.properties
    

    Also, we can also disable the auto primitive feature only for a set of data by providing a regex pattern. If you want to disable the auto primitive feature only for the above data set you configure the following in [EI_HOME]/conf/synapse.properties file.

    synapse.commons.json.output.disableAutoPrimitive.regex=^-?(0|[1-9][0-9]*)(.[0-9]+)?$ After configuring the above please restart the servers.

    [1]-https://docs.wso2.com/display/EI650/Working+with+JSON+Message+Payloads