In IBM MobileFirst 7.0, I created a SOAP adapter by pointing MobileFirst Platform Studio to a WSDL running on a local web server. When calling the SOAP adapter, which converts JSON to XML then when the response is received from XML back into JSON, it is setting number (integer, decimal) and boolean values in the JSON returned as strings i.e. surrounding them in double quotes in the response instead of leaving them unquoted. I did not change anything in the adapter that was auto generated by MFP Studio. It is my understanding that in JSON, booleans and numbers as well as nulls are not quoted. I also have a non-MobileFirst web server running via Spring Boot using WebServiceGatewaySupport to call the same SOAP service and @ResponseBody annotation to have it automatically return JSON and numbers and booleans are NOT in double quotes within the strings returned.
Is it expected that MobileFirst/Worklight returns everything as a String within the JSON body? If so, why? If not, any ideas on what I may need to do in order for this not to happen and for it to leave numbers and booleans unquoted?
Below are the relevant portions of the WSDL and the JSON request/responses to/from the Worklight SOAP adapter.
<xs:element name="customerFoodOrderRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="customerId" type="xs:int"/>
<xs:element name="dateTime" type="xs:dateTime"/>
<xs:element name="item" type="xs:string"/>
<xs:element name="amount" type="tns:money"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="money">
<xs:restriction base="xs:decimal">
<xs:fractionDigits value="2"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="customerFoodOrderResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="success" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getRecentFoodOrdersForCustomerRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="customerId" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getRecentFoodOrdersForCustomerResponse">
<xs:complexType>
<xs:sequence maxOccurs="unbounded" minOccurs="0">
<xs:element name="foodOrders" type="tns:foodOrder"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="foodOrder">
<xs:sequence>
<xs:element name="dateTime" type="xs:dateTime"/>
<xs:element name="item" type="xs:string"/>
<xs:element name="amount" type="tns:money"/>
</xs:sequence>
</xs:complexType>
JSON Response #1 (amount is an xs:decimal wrapped in a SimpleType named money, but it is being output to JSON as a string)
{
"Envelope": {
"Body": {
"getRecentFoodOrdersForCustomerResponse": {
"foodOrders": {
"amount": "10",
"dateTime": "2015-02-14T12:00:00.123-07:00",
"item": "MyItem"
},
"ns2": "http:\/\/company.com\/demo\/demo-producing-web-service"
}
},
"Header": "",
"SOAP-ENV": "http:\/\/schemas.xmlsoap.org\/soap\/envelope\/"
},
"errors": [
],
"info": [
],
"isSuccessful": true,
"responseHeaders": {
"Accept": "text\/xml, text\/html, image\/gif, image\/jpeg, *; q=.2, *\/*; q=.2",
"Content-Length": "444",
"Content-Type": "text\/xml;charset=utf-8",
"Date": "Wed, 20 May 2015 02:58:26 GMT",
"SOAPAction": "\"\"",
"Server": "Apache-Coyote\/1.1"
},
"responseTime": 328,
"statusCode": 200,
"statusReason": "OK",
"totalTime": 359,
"warnings": [
]
}
JSON Response #2 with boolean value for success in double quotes:
{
"Envelope": {
"Body": {
"customerFoodOrderResponse": {
"ns2": "http:\/\/company.com\/demo\/demo-producing-web-service",
"success": "true"
}
},
"Header": "",
"SOAP-ENV": "http:\/\/schemas.xmlsoap.org\/soap\/envelope\/"
},
"errors": [
],
"info": [
],
"isSuccessful": true,
"responseHeaders": {
"Accept": "text\/xml, text\/html, image\/gif, image\/jpeg, *; q=.2, *\/*; q=.2",
"Content-Length": "304",
"Content-Type": "text\/xml;charset=utf-8",
"Date": "Wed, 20 May 2015 02:46:02 GMT",
"SOAPAction": "\"\"",
"Server": "Apache-Coyote\/1.1"
},
"responseTime": 764,
"statusCode": 200,
"statusReason": "OK",
"totalTime": 796,
"warnings": [
]
}
JSON Response #3 (Customer ID is being wrapped in double quotes even though it is defined as an xs:int)
"customer": {
"accountNumber": "11127174",
"firstName": "JOHN",
"id": "200",
"lastName": "DOE",
"status": "None"
},
The customer definition from the WSDL
<xs:complexType name="customer">
<xs:sequence>
<xs:element name="id" type="xs:int"/>
<xs:element minOccurs="1" name="firstName" nillable="false" type="xs:string"/>
<xs:element minOccurs="1" name="lastName" nillable="false" type="xs:string"/>
<xs:element minOccurs="1" name="status" nillable="false" type="tns:status"/>
<xs:element name="accountNumber" type="xs:string"/>
</xs:sequence>
</xs:complexType>