Hi,

Can you try adding <?xml-multiple?> (Processing Instruction) element to the
payload and check.

Best Regards,
Malaka


On Mon, Jul 21, 2014 at 2:27 PM, Jay <janaka.n.ranathu...@gmail.com> wrote:

> Hi,
>
> I am calling an endpoint which requires sending numeric keys in objects in
> the following format:
> {"1" : "some value"}
>
> However, when processing this using a script mediator, the numeric key is
> converted in to a primitive number as follows:
> {1 : "some value"}
>
> which is not accepted by the script mediator when setting the payload using
> setPayloadJSON.
>
> This problem can also be seen when sending numeric values (not keys).
> Although the values are numeric, the backend does not accept these values
> if
> they are not sent as strings. e.g. {"key":"123"} is converted to
> {"key":123}
> which is not accepted.
>
>
> I managed to circumvent this problem by processing the payload via XML:
>
> payloadXML = mc.getPayloadXML();
>                                         var customFields =
> mc.getProperty("uri.var.customFields");
>
>                                         var jsonObj =
> eval("("+customFields+")");
>                                         var customFieldsTag = <cf/>;
>                                         for(var key in  jsonObj){
>                                                 var val = jsonObj[key];
>                                                 customFieldsTag.cf +=
> <_JsonReader_PD_{key}>{val}</_JsonReader_PD_{key}>;
>                                 }
>
>                                         payloadXML.cf = customFieldsTag;
>
>                                         mc.setPayloadXML(payloadXML);
>
> However, when processing the payload via XML, when there is only one
> element
> within a JSON array, e.g. {"jsonaray" : ["some value"]}
>
> this is processed as a single value (not within an array) and sent by the
> XML processor as {"jsonarray" : "some value"}
>
> Furthermore, when sending an empty value within a JSON array (which is
> required by the backend) and processing using XML, e.g. {"jsonarray" :
> ["some value", ""]}, the empty value is converted to *null*, which is not
> accepted by the backend.
>
>
> I would appreciate if someone could give me a solution to either;
> * Send numeric keys and values as strings within a JSON payload without
> them
> being processed in to numeric primitives.
> * Send a single value within a JSON array without it being reprocessed as a
> single key value pair by the XML-to-JSON processor.
>
>
> Thanks,
>
>
>
>
> --
> View this message in context:
> http://wso2-oxygen-tank.10903.n7.nabble.com/ESB-Problems-sending-numeric-keys-in-JSON-Payloads-tp99789.html
> Sent from the WSO2 Development mailing list archive at Nabble.com.
> _______________________________________________
> Dev mailing list
> Dev@wso2.org
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>



-- 

Best Regards,

Malaka Silva
Senior Tech Lead
M: +94 777 219 791
Tel : 94 11 214 5345
Fax :94 11 2145300
Skype : malaka.sampath.silva
LinkedIn : http://www.linkedin.com/pub/malaka-silva/6/33/77
Blog : http://mrmalakasilva.blogspot.com/

WSO2, Inc.
lean . enterprise . middleware
http://www.wso2.com/
http://www.wso2.com/about/team/malaka-silva/
<http://wso2.com/about/team/malaka-silva/>

Save a tree -Conserve nature & Save the world for your future. Print this
email only if it is absolutely necessary.
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to