WSO2 returning string as infinity number - json

We are using WSO2 as our API manager to communicate with our backend (nodeJS) services. We are seeing a strange issue with one endpoint where we are requesting a product JSON and are getting a JSON parsing error because of an Infinity number. The original data contains a string however which is "3E10266". When we request the product JSON from Mongo directly from the service we get the correct string back:
{
"_id": 800285,
"SupplierReferenceDescription": "3E10266",
"SupplierReferenceNumber": "3E10266",
}
However requesting this through WSO I get the following:
{
"_id":800285,
"SupplierReferenceDescription":3E+10266,
"SupplierReferenceNumber":3E+10266
}
Which cannot be parsed by our frontend service. It looks like WSO2 is doing some translations on the JSON, can I disable this behaviour? I have found an issue that looks like mine but no clear solution is given: json conversion issue in wso2 API Manager

Related

Can the Azure Storage REST API send the response in JSON format?

I am developing a library for working with various types of cloud based queue services.
One of those services is the Azure Queue Storage REST API.
For the Amazon SQS service I can send an Accept: application/json header and the response is in JSON format.
Since JSON is a format that is supported by many APIs and XML is not fun to work with, I would prefer the Azure Storage REST API to also return a response in JSON format.
I have tried to set the Accept: application/json header to no avail. The responses are all in XML format with Content-Type: application/xml, which is obviously not what I was asking for.
Currently all code is in C with dependencies on a couple of libraries, including cURL and jansson, although for this question that doesn't really matter. It's just that I would like the library to be as simple and lightweight as possible.
I have a hard time digging through all kinds of documentation. Most topics I can find are about sending JSON within a message. But that's not what I'm going for.
Is it even possible to receive the actual responses in JSON? I would really like to drop my libxml2 dependency.
As pointed by #Tom Because the documentation is stating that it only return XML, I would personally write an azure function who becomes an adaptor which basically takes your request, sends it to azure queue storage, retrieves the xml response and then converts the xml response to json and return the json to the caller (which will be your C code).
A sample python code to convert xml to json is shown below:
import xmltodict
import json
text = ''
xpars = xmltodict.parse(text)
json = json.dumps(xpars)
print(json)
A sample xml message
text = '<QueueMessagesList>
<QueueMessage>
<MessageId>string-message-id</MessageId>
<InsertionTime>insertion-time</InsertionTime>
<ExpirationTime>expiration-time</ExpirationTime>
<PopReceipt>opaque-string-receipt-data</PopReceipt>
<TimeNextVisible>time-next-visible</TimeNextVisible>
<DequeueCount>integer</DequeueCount>
<MessageText>message-body</MessageText>
</QueueMessage>
</QueueMessagesList>'
And the response will be :
{
"QueueMessagesList": {
"QueueMessage": {
"MessageId": "string-message-id",
"InsertionTime": "insertion-time",
"ExpirationTime": "expiration-time",
"PopReceipt": "opaque-string-receipt-data",
"TimeNextVisible": "time-next-visible",
"DequeueCount": "integer",
"MessageText": "message-body"
}
}
}
Please Note: This whole thing can also be done using a Logic App in azure.
I have only shown the XML to JSON converter part here, but it is really straightforward to write an HTTP Trigger Azure Function to do the same. Or you can even write this converter into your C code as well.
Hope this helps you in moving on with your library development.

cannot get document id using box view api

In my app, after get "https://dl.boxcloud.com/*" url and send it to the View API, I receive this error:
{
message: "JSON parse error - No JSON object could be decoded"
type: "error"
request_id: "3ef12abcaf7a4c5abab5fb0d3959255e"
}
you can use this chrome extension to recreate this error
https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo
I tried with the other rest clients and it work correctly. Except in my app and the extension above.
I tried with the other rest clients and it work correctly. Except in my app and the extension above.
If this is the case, it's likely that the client you're using isn't actually sending properly formatted JSON. One way to debug this would be to output the raw HTTP request the client is sending and ensuring that it's actually sending the JSON properly.

Can't extract data from my json response-Web Java EE Application

I developed a web service that extracts messages from a database and returns an object containing a table and a string, as a json response.
The problem is that I can't extract data from the client application when I consume the web service.
This is the reponse I get when I run the web service
{
"msgTabl":
{
"list":
[
{"contenu":"aid mabroukk","dateEnvoi":"2014-07-30","frommm":"voeuxmsg","id":0,"idu":0,"numExp":50840749},
{"contenu":222222222222,"dateEnvoi":222222,"frommm":222222222222,"id":0,"idu":0,"numExp":2222222},
{"contenu":3333333333,"dateEnvoi":3333333333,"frommm":333333333,"id":0,"idu":0,"numExp":33333333333}
],
"test":"ok"
}
}
I tried to take the json content from my client application, but I couldn't because of the structure of my json reponse. I don't know why this "msgTabl" is shown at the beginning.
You can use
reponse['msgTabl']
in your client application to get the right structure you want

Why my wso2 esb api return only the first property of the original json?

I'm using wso2 esb 4.0.3.
I used cxf to create a jaxrs api. The first resource is simple. I use SOAP-UI to issue an HTTP GET to this resource, and it returns a json string with the data I expected. Like:
{"id":"some id", "name": "some name", "when":"some time".......}
I created an API in wso2 esb. A resource is configured to call the backend resource mentioned above. When I call this resource using SOAP-UI, I get a json string, but with only the first property of the data. Like:
{"id":"some id"}
What is causing this problem, and how can I fix this?

json conversion issue in wso2 API Manager

We are trying to use wso2 api manager to access some of our RESTful services.
The rest services expect a json payload. When json request is sent to api manager it converts the json request to xml and again while forwarding to the actual endpoint it converts to json back.
The resulting json is not matching exactly the original request in one of our cases.
For instance if the rquest contains an array of elements and if only one element is passed in the array then when api manager forwards the request to the endpoint the array characters ([,]) are removed.
eg.
our original request was
{
"entities": [
{
"name":"KK71CP20000523A1",
"descr":"VaS",
"mnf":"BCT",
"mdlyr":"2012"
}
]
}
the request sent by api manager was
{
"entities":
{
"name":"KK71CP20000523A1",
"descr":"VaS",
"mnf":"BCT",
"mdlyr":"2012"
}
}
The array wrapping is removed under entities element.
When the number of elements is more than one then the array characters are retained.
We faced the same issue in ESB as well previously. But we worked around the issue by extending the default JSONMessageFormatter and using the seriliazeAsArray method available in the jettison library.
But we dont want to do this customization in API Manager.
Is there a better way of fixing this issue? Any patch available from wso2 to fix this?
All carbon products comes with same message builders and formatters, for your case can you check with JSONStreambuilder and formatter.
Look at this reference,