Re: [Dev] [ESB] Problems sending numeric keys in JSON Payloads
Hi, If any of the above does not work use a class mediator to do generate the json payload required. eg:- public boolean mediate(MessageContext mc) { StringBuilder sb = new StringBuilder(); //generate the required payload org.apache.axis2.context.MessageContext axis2MC = ((Axis2MessageContext)mc).getAxis2MessageContext(); JsonUtil.newJsonPayload(axis2MC, sb.toString(), true, true); return true; } [1] https://docs.wso2.com/display/ESB481/Class+Mediator Best Regards, Malaka On Wed, Aug 13, 2014 at 1:18 PM, Jay janaka.n.ranathu...@gmail.com wrote: Hi Malaka, My initial payload is as follows: payloadFactory media-type=xml format jsonObject xmlns= nameJanaka/name descriptionDesc/description statusopen/status leadUserA/leadUser currencyLKR/currency cust114520/cust ?xml-multiple?tags/tags /jsonObject /format args / /payloadFactory In script I'm adding some additional parameters (value and tags.tags should be send as array even if there are only one) to above payload as: ** This will work properly if user send tags in request. But my problem is if user doesn't send tags parameter tags element will remove from payload and ?xml-multiple? is applying to value element and it will send as array which back end will not accept. I have two options, [1]. Remove ?xml-multiple? from payload if user doesn't send any tags [2]. Add PIs in Script mediator other than in payloadFactory. What is your idea to solve this problem? Regards, Janaka -- View this message in context: http://wso2-oxygen-tank.10903.n7.nabble.com/ESB-Problems-sending-numeric-keys-in-JSON-Payloads-tp99789p101325.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
Re: [Dev] [ESB] Problems sending numeric keys in JSON Payloads
Hi Malaka, My initial payload is as follows: payloadFactory media-type=xml format jsonObject xmlns= nameJanaka/name descriptionDesc/description statusopen/status leadUserA/leadUser currencyLKR/currency cust114520/cust ?xml-multiple?tags/tags /jsonObject /format args / /payloadFactory In script I'm adding some additional parameters (value and tags.tags should be send as array even if there are only one) to above payload as: ** This will work properly if user send tags in request. But my problem is if user doesn't send tags parameter tags element will remove from payload and ?xml-multiple? is applying to value element and it will send as array which back end will not accept. I have two options, [1]. Remove ?xml-multiple? from payload if user doesn't send any tags [2]. Add PIs in Script mediator other than in payloadFactory. What is your idea to solve this problem? Regards, Janaka -- View this message in context: http://wso2-oxygen-tank.10903.n7.nabble.com/ESB-Problems-sending-numeric-keys-in-JSON-Payloads-tp99789p101325.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
Re: [Dev] [ESB] Problems sending numeric keys in JSON Payloads
Hi Malaka, I have already tried this solution and this will work only if we declared ?xml-multiple? in payloadFactory mediator. But if i set ?xml-multiple? in script mediator it will ignore. Following is my complete config: payloadFactory media-type=xml format jsonObject xmlns=?xml-multiple? tags jsonElementTestTag/jsonElement /tags nameJanaka/name /jsonObject /format args / /payloadFactory property name=messageType value=application/json scope=axis2 type=STRING / log level=full/ log property name=Janaka expression=json-eval($.) / /log And the output: [2014-08-12 12:17:41,485] INFO - LogMediator To: /services/ClevertimCRM_createOpportunity, MessageID: urn:uuid:73a98f19 -1a7e-4fbe-ba68-2ef530419845, Direction: request, Envelope: ?xml version=1.0 encoding=utf-8?soapenv:Envelope xmln s:soapenv=http://schemas.xmlsoap.org/soap/envelope/;soapenv:BodyjsonObject?xml-multiple ?tagsjsonElementTes tTag/jsonElement/tagsnameJanaka/namescriptArrayjsonElementTestTag/jsonElement/scriptArray/jsonObject/ soapenv:Body/soapenv:Envelope [2014-08-12 12:17:41,486] INFO - LogMediator To: /services/ClevertimCRM_createOpportunity, MessageID: urn:uuid:73a98f19 -1a7e-4fbe-ba68-2ef530419845, Direction: request, Janaka = {tags:[TestTag],name:Janaka,scriptArray:TestTag} I need to send scriptArray also as an array. Regards, Janaka -- View this message in context: http://wso2-oxygen-tank.10903.n7.nabble.com/ESB-Problems-sending-numeric-keys-in-JSON-Payloads-tp99789p101240.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
Re: [Dev] [ESB] Problems sending numeric keys in JSON Payloads
Please share your configuration with the script mediator. On Tue, Aug 12, 2014 at 12:23 PM, Jay janaka.n.ranathu...@gmail.com wrote: Hi Malaka, I have already tried this solution and this will work only if we declared ?xml-multiple? in payloadFactory mediator. But if i set ?xml-multiple? in script mediator it will ignore. Following is my complete config: payloadFactory media-type=xml format jsonObject xmlns=?xml-multiple? tags jsonElementTestTag/jsonElement /tags nameJanaka/name /jsonObject /format args / /payloadFactory property name=messageType value=application/json scope=axis2 type=STRING / log level=full/ log property name=Janaka expression=json-eval($.) / /log And the output: [2014-08-12 12:17:41,485] INFO - LogMediator To: /services/ClevertimCRM_createOpportunity, MessageID: urn:uuid:73a98f19 -1a7e-4fbe-ba68-2ef530419845, Direction: request, Envelope: ?xml version=1.0 encoding=utf-8?soapenv:Envelope xmln s:soapenv=http://schemas.xmlsoap.org/soap/envelope/ soapenv:BodyjsonObject?xml-multiple ?tagsjsonElementTes tTag/jsonElement/tagsnameJanaka/namescriptArrayjsonElementTestTag/jsonElement/scriptArray/jsonObject/ soapenv:Body/soapenv:Envelope [2014-08-12 12:17:41,486] INFO - LogMediator To: /services/ClevertimCRM_createOpportunity, MessageID: urn:uuid:73a98f19 -1a7e-4fbe-ba68-2ef530419845, Direction: request, Janaka = {tags:[TestTag],name:Janaka,scriptArray:TestTag} I need to send scriptArray also as an array. Regards, Janaka -- View this message in context: http://wso2-oxygen-tank.10903.n7.nabble.com/ESB-Problems-sending-numeric-keys-in-JSON-Payloads-tp99789p101240.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
Re: [Dev] [ESB] Problems sending numeric keys in JSON Payloads
Hi Malaka, Following is my configuration with inline script mediator: template name=createOpportunity xmlns=http://ws.apache.org/ns/synapse; sequence payloadFactory media-type=xml format jsonObject xmlns=?xml-multiple? tags jsonElementTestTag/jsonElement /tags nameJanaka/name /jsonObject /format args / /payloadFactory ** property name=messageType value=application/json scope=axis2 type=STRING / log level=full/ log property name=Janaka expression=json-eval($.) / /log call endpoint http method=post uri-template={uri.var.apiUrl}/opportunity / /endpoint /call /sequence /template -- View this message in context: http://wso2-oxygen-tank.10903.n7.nabble.com/ESB-Problems-sending-numeric-keys-in-JSON-Payloads-tp99789p101262.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
Re: [Dev] [ESB] Problems sending numeric keys in JSON Payloads
Hi, There is not script mediator used in the configuration you sent. Following is the output for that. [2014-08-12 16:08:12,390] DEBUG - wire POST /services/pass1.pass1HttpSoap12Endpoint HTTP/1.1[\r][\n] [2014-08-12 16:08:12,390] DEBUG - wire Content-Type: application/soap+xml; charset=UTF-8; action=urn:mediate[\r][\n] [2014-08-12 16:08:12,391] DEBUG - wire Cookie: region3_registry_menu=visible; menuPanel=visible; menuPanelType=main; region1_configure_menu=none; region4_monitor_menu=none; region5_tools_menu=none; requestedURI=../../carbon/service-mgt/index.jsp?region=region1item=services_list_menu; JSESSIONID=A652FAE3D43E1ACEF72AB6060609AA68; current-breadcrumb=manage_menu%2Cservices_menu%2Cservices_list_menu%23; MSG14078183094500.4606495099950271=true; MSG14078183198250.2019032806534964=true; MSG14078183337640.8369394687123034=true; MSG14078185781460.4222625543797929=true; MSG14078186327360.3619132076277993=true; MSG14078186445170.8474369217867975=true; MSG14078189363290.09887523460529613=true; MSG14078202820720.3139562562501682=true; MSG14078213631700.20356205159007335=true; MSG14078380807410.0045559539948989425=true[\r][\n] [2014-08-12 16:08:12,391] DEBUG - wire User-Agent: Axis2[\r][\n] [2014-08-12 16:08:12,391] DEBUG - wire Host: 10.100.0.29:8280[\r][\n] [2014-08-12 16:08:12,391] DEBUG - wire Transfer-Encoding: chunked[\r][\n] [2014-08-12 16:08:12,391] DEBUG - wire [\r][\n] [2014-08-12 16:08:12,391] DEBUG - wire a0[\r][\n] [2014-08-12 16:08:12,392] DEBUG - wire ?xml version=1.0 encoding=UTF-8?soapenv:Envelope xmlns:soapenv= http://www.w3.org/2003/05/soap-envelope soapenv:Body/soapenv:Body/soapenv:Envelope[\r][\n] [2014-08-12 16:08:12,392] DEBUG - wire 0[\r][\n] [2014-08-12 16:08:12,392] DEBUG - wire [\r][\n] [2014-08-12 16:08:12,396] INFO - LogMediator To: /services/pass1.pass1HttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:52c1fe22-4f6f-4539-a39f-4eedd9d13ae3, Direction: request, Envelope: ?xml version=1.0 encoding=utf-8?soapenv:Envelope xmlns:soapenv= http://www.w3.org/2003/05/soap-envelope;soapenv:BodyjsonObject?xml-multiple ?tagsjsonElementTestTag/jsonElement/tagsnameJanaka/name/jsonObject/soapenv:Body/soapenv:Envelope [2014-08-12 16:08:12,399] INFO - LogMediator To: /services/pass1.pass1HttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:52c1fe22-4f6f-4539-a39f-4eedd9d13ae3, Direction: request, Janaka = {tags:[TestTag],name:Janaka} [2014-08-12 16:08:12,403] DEBUG - wire POST /service/echo HTTP/1.1[\r][\n] [2014-08-12 16:08:12,404] DEBUG - wire Content-Type: application/json; charset=UTF-8[\r][\n] [2014-08-12 16:08:12,404] DEBUG - wire Cookie: region3_registry_menu=visible; menuPanel=visible; menuPanelType=main; region1_configure_menu=none; region4_monitor_menu=none; region5_tools_menu=none; requestedURI=../../carbon/service-mgt/index.jsp?region=region1item=services_list_menu; JSESSIONID=A652FAE3D43E1ACEF72AB6060609AA68; current-breadcrumb=manage_menu%2Cservices_menu%2Cservices_list_menu%23; MSG14078183094500.4606495099950271=true; MSG14078183198250.2019032806534964=true; MSG14078183337640.8369394687123034=true; MSG14078185781460.4222625543797929=true; MSG14078186327360.3619132076277993=true; MSG14078186445170.8474369217867975=true; MSG14078189363290.09887523460529613=true; MSG14078202820720.3139562562501682=true; MSG14078213631700.20356205159007335=true; MSG14078380807410.0045559539948989425=true[\r][\n] [2014-08-12 16:08:12,405] DEBUG - wire Transfer-Encoding: chunked[\r][\n] [2014-08-12 16:08:12,405] DEBUG - wire Host: localhost:9000[\r][\n] [2014-08-12 16:08:12,405] DEBUG - wire Connection: Keep-Alive[\r][\n] [2014-08-12 16:08:12,405] DEBUG - wire User-Agent: Synapse-HttpComponents-NIO[\r][\n] [2014-08-12 16:08:12,405] DEBUG - wire [\r][\n] [2014-08-12 16:08:12,407] DEBUG - wire 24[\r][\n] [2014-08-12 16:08:12,407] DEBUG - wire {tags:[TestTag],name:Janaka}[\r][\n] [2014-08-12 16:08:12,407] DEBUG - wire 0[\r][\n] [2014-08-12 16:08:12,408] DEBUG - wire [\r][\n] [2014-08-12 16:08:12,408] DEBUG - wire HTTP/1.1 200 OK[\r][\n] [2014-08-12 16:08:12,408] DEBUG - wire Server: Apache-Coyote/1.1[\r][\n] [2014-08-12 16:08:12,408] DEBUG - wire port: 9000[\r][\n] [2014-08-12 16:08:12,409] DEBUG - wire Content-Type: application/json;charset=UTF-8[\r][\n] [2014-08-12 16:08:12,409] DEBUG - wire Content-Length: 36[\r][\n] [2014-08-12 16:08:12,409] DEBUG - wire Date: Tue, 12 Aug 2014 10:38:12 GMT[\r][\n] [2014-08-12 16:08:12,409] DEBUG - wire [\r][\n] [2014-08-12 16:08:12,410] DEBUG - wire {tags:[TestTag],name:Janaka} [2014-08-12 16:08:12,414] DEBUG - wire HTTP/1.1 200 OK[\r][\n] [2014-08-12 16:08:12,416] DEBUG - wire Content-Type: application/json; charset=UTF-8[\r][\n] [2014-08-12 16:08:12,416] DEBUG - wire port: 9000[\r][\n] [2014-08-12 16:08:12,416] DEBUG - wire Server: Apache-Coyote/1.1[\r][\n] [2014-08-12 16:08:12,417] DEBUG - wire Date: Tue, 12 Aug 2014 10:38:12 GMT[\r][\n] [2014-08-12
Re: [Dev] [ESB] Problems sending numeric keys in JSON Payloads
Hi, My understanding is your requirement is to achieve {tags:[TestTag]} you can easily done this with following. Combining payload mediator and script mediator. payloadFactory media-type=xml format jsonObject xmlns=?xml-multiple?/jsonObject /format args/ /payloadFactory script language=jspayloadXML = mc.getPayloadXML(); payloadXML.jsonObject += lt;?xml-multiple?gt;lt;tagsgt;lt;jsonElementgt;TestTaglt;/jsonElementgt;lt;/tagsamp;gt; print(payloadXML); mc.setPayloadXML(payloadXML);/script Moreover this can also be done using given samples in [1] [1] https://docs.wso2.com/display/ESB481/JSON+Support Best Regards, Malaka On Tue, Aug 12, 2014 at 4:11 PM, Malaka Silva mal...@wso2.com wrote: Hi, There is not script mediator used in the configuration you sent. Following is the output for that. [2014-08-12 16:08:12,390] DEBUG - wire POST /services/pass1.pass1HttpSoap12Endpoint HTTP/1.1[\r][\n] [2014-08-12 16:08:12,390] DEBUG - wire Content-Type: application/soap+xml; charset=UTF-8; action=urn:mediate[\r][\n] [2014-08-12 16:08:12,391] DEBUG - wire Cookie: region3_registry_menu=visible; menuPanel=visible; menuPanelType=main; region1_configure_menu=none; region4_monitor_menu=none; region5_tools_menu=none; requestedURI=../../carbon/service-mgt/index.jsp?region=region1item=services_list_menu; JSESSIONID=A652FAE3D43E1ACEF72AB6060609AA68; current-breadcrumb=manage_menu%2Cservices_menu%2Cservices_list_menu%23; MSG14078183094500.4606495099950271=true; MSG14078183198250.2019032806534964=true; MSG14078183337640.8369394687123034=true; MSG14078185781460.4222625543797929=true; MSG14078186327360.3619132076277993=true; MSG14078186445170.8474369217867975=true; MSG14078189363290.09887523460529613=true; MSG14078202820720.3139562562501682=true; MSG14078213631700.20356205159007335=true; MSG14078380807410.0045559539948989425=true[\r][\n] [2014-08-12 16:08:12,391] DEBUG - wire User-Agent: Axis2[\r][\n] [2014-08-12 16:08:12,391] DEBUG - wire Host: 10.100.0.29:8280[\r][\n] [2014-08-12 16:08:12,391] DEBUG - wire Transfer-Encoding: chunked[\r][\n] [2014-08-12 16:08:12,391] DEBUG - wire [\r][\n] [2014-08-12 16:08:12,391] DEBUG - wire a0[\r][\n] [2014-08-12 16:08:12,392] DEBUG - wire ?xml version=1.0 encoding=UTF-8?soapenv:Envelope xmlns:soapenv= http://www.w3.org/2003/05/soap-envelope soapenv:Body/soapenv:Body/soapenv:Envelope[\r][\n] [2014-08-12 16:08:12,392] DEBUG - wire 0[\r][\n] [2014-08-12 16:08:12,392] DEBUG - wire [\r][\n] [2014-08-12 16:08:12,396] INFO - LogMediator To: /services/pass1.pass1HttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:52c1fe22-4f6f-4539-a39f-4eedd9d13ae3, Direction: request, Envelope: ?xml version=1.0 encoding=utf-8?soapenv:Envelope xmlns:soapenv= http://www.w3.org/2003/05/soap-envelope;soapenv:BodyjsonObject?xml-multiple ?tagsjsonElementTestTag/jsonElement/tagsnameJanaka/name/jsonObject/soapenv:Body/soapenv:Envelope [2014-08-12 16:08:12,399] INFO - LogMediator To: /services/pass1.pass1HttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:52c1fe22-4f6f-4539-a39f-4eedd9d13ae3, Direction: request, Janaka = {tags:[TestTag],name:Janaka} [2014-08-12 16:08:12,403] DEBUG - wire POST /service/echo HTTP/1.1[\r][\n] [2014-08-12 16:08:12,404] DEBUG - wire Content-Type: application/json; charset=UTF-8[\r][\n] [2014-08-12 16:08:12,404] DEBUG - wire Cookie: region3_registry_menu=visible; menuPanel=visible; menuPanelType=main; region1_configure_menu=none; region4_monitor_menu=none; region5_tools_menu=none; requestedURI=../../carbon/service-mgt/index.jsp?region=region1item=services_list_menu; JSESSIONID=A652FAE3D43E1ACEF72AB6060609AA68; current-breadcrumb=manage_menu%2Cservices_menu%2Cservices_list_menu%23; MSG14078183094500.4606495099950271=true; MSG14078183198250.2019032806534964=true; MSG14078183337640.8369394687123034=true; MSG14078185781460.4222625543797929=true; MSG14078186327360.3619132076277993=true; MSG14078186445170.8474369217867975=true; MSG14078189363290.09887523460529613=true; MSG14078202820720.3139562562501682=true; MSG14078213631700.20356205159007335=true; MSG14078380807410.0045559539948989425=true[\r][\n] [2014-08-12 16:08:12,405] DEBUG - wire Transfer-Encoding: chunked[\r][\n] [2014-08-12 16:08:12,405] DEBUG - wire Host: localhost:9000[\r][\n] [2014-08-12 16:08:12,405] DEBUG - wire Connection: Keep-Alive[\r][\n] [2014-08-12 16:08:12,405] DEBUG - wire User-Agent: Synapse-HttpComponents-NIO[\r][\n] [2014-08-12 16:08:12,405] DEBUG - wire [\r][\n] [2014-08-12 16:08:12,407] DEBUG - wire 24[\r][\n] [2014-08-12 16:08:12,407] DEBUG - wire {tags:[TestTag],name:Janaka}[\r][\n] [2014-08-12 16:08:12,407] DEBUG - wire 0[\r][\n] [2014-08-12 16:08:12,408] DEBUG - wire [\r][\n] [2014-08-12 16:08:12,408] DEBUG - wire HTTP/1.1 200 OK[\r][\n] [2014-08-12
Re: [Dev] [ESB] Problems sending numeric keys in JSON Payloads
/janaka.n.ranathunga http://lk.linkedin.com/in/janakaranathunga https://plus.google.com/+janakaranathunga -- View this message in context: Re: [Dev] [ESB] Problems sending numeric keys in JSON Payloads http://wso2-oxygen-tank.10903.n7.nabble.com/ESB-Problems-sending-numeric-keys-in-JSON-Payloads-tp99789p100277.html Sent from the WSO2 Development mailing list archive http://wso2-oxygen-tank.10903.n7.nabble.com/WSO2-Development-f3.html 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
Re: [Dev] [ESB] Problems sending numeric keys in JSON Payloads
Hi, Try following var tagElement=jsonObject?xml-multiple?tagsjsonElement TestTag/jsonElement/tags/jsonObject; On Wed, Jul 23, 2014 at 1:52 PM, Jay janaka.n.ranathu...@gmail.com wrote: Hi Malaka, I have tried with your solution but it didn't work. following is my javascript code: var tagElement=tags?xml-multiple?jsonElementTestTag/jsonElement/tags; payloadXML.tags=tagElement; This will create JSON payload as : {tags:TestTag} But the requirement is: {tags:[TestTag]} I have enabled following message builder/formatter as well, messageFormatter contentType=application/json class=org.apache.synapse.commons.json.JsonFormatter/ messageBuilder contentType=application/json class=org.apache.synapse.commons.json.JsonBuilder/ Regards, Janaka -- View this message in context: http://wso2-oxygen-tank.10903.n7.nabble.com/ESB-Problems-sending-numeric-keys-in-JSON-Payloads-tp99789p11.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
Re: [Dev] [ESB] Problems sending numeric keys in JSON Payloads
Hi Malaka, I tried with this and still having a problem. var a=jsonObject?xml-multiple?tagsjsonElementTestTag/jsonElement/tags/jsonObject; Output: jsonObject:{tags:TestTag} Regards, Janaka On Thu, Jul 24, 2014 at 5:50 PM, Malaka Silva [via WSO2 Oxygen Tank] ml-node+s10903n100231...@n7.nabble.com wrote: Hi, Try following var tagElement=jsonObject?xml-multiple?tagsjsonElement TestTag/jsonElement/tags/jsonObject; On Wed, Jul 23, 2014 at 1:52 PM, Jay [hidden email] http://user/SendEmail.jtp?type=nodenode=100231i=0 wrote: Hi Malaka, I have tried with your solution but it didn't work. following is my javascript code: var tagElement=tags?xml-multiple?jsonElementTestTag/jsonElement/tags; payloadXML.tags=tagElement; This will create JSON payload as : {tags:TestTag} But the requirement is: {tags:[TestTag]} I have enabled following message builder/formatter as well, messageFormatter contentType=application/json class=org.apache.synapse.commons.json.JsonFormatter/ messageBuilder contentType=application/json class=org.apache.synapse.commons.json.JsonBuilder/ Regards, Janaka -- View this message in context: http://wso2-oxygen-tank.10903.n7.nabble.com/ESB-Problems-sending-numeric-keys-in-JSON-Payloads-tp99789p11.html Sent from the WSO2 Development mailing list archive at Nabble.com. ___ Dev mailing list [hidden email] http://user/SendEmail.jtp?type=nodenode=100231i=1 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 [hidden email] http://user/SendEmail.jtp?type=nodenode=100231i=2 http://wso2.org/cgi-bin/mailman/listinfo/dev -- If you reply to this email, your message will be added to the discussion below: http://wso2-oxygen-tank.10903.n7.nabble.com/ESB-Problems-sending-numeric-keys-in-JSON-Payloads-tp99789p100231.html To unsubscribe from [ESB] Problems sending numeric keys in JSON Payloads, click here http://wso2-oxygen-tank.10903.n7.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=99789code=amFuYWthLm4ucmFuYXRodW5nYUBnbWFpbC5jb218OTk3ODl8MTg3OTc3NTUwOA== . NAML http://wso2-oxygen-tank.10903.n7.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml -- *Janaka Ranathunga* * Senior Software Engineer* Tel: +94 11 256 9150 | Mobile: +94 71 168 3232 janaka.n.ranathu...@gmail.com https://www.facebook.com/janaka.n.ranathunga http://lk.linkedin.com/in/janakaranathunga https://plus.google.com/+janakaranathunga -- View this message in context: http://wso2-oxygen-tank.10903.n7.nabble.com/ESB-Problems-sending-numeric-keys-in-JSON-Payloads-tp99789p100277.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
Re: [Dev] [ESB] Problems sending numeric keys in JSON Payloads
Hi Malaka, I have tried with your solution but it didn't work. following is my javascript code: var tagElement=tags?xml-multiple?jsonElementTestTag/jsonElement/tags; payloadXML.tags=tagElement; This will create JSON payload as : {tags:TestTag} But the requirement is: {tags:[TestTag]} I have enabled following message builder/formatter as well, messageFormatter contentType=application/json class=org.apache.synapse.commons.json.JsonFormatter/ messageBuilder contentType=application/json class=org.apache.synapse.commons.json.JsonBuilder/ Regards, Janaka -- View this message in context: http://wso2-oxygen-tank.10903.n7.nabble.com/ESB-Problems-sending-numeric-keys-in-JSON-Payloads-tp99789p11.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
Re: [Dev] [ESB] Problems sending numeric keys in JSON Payloads
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
[Dev] [ESB] Problems sending numeric keys in JSON Payloads
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