在 IBM MobileFirst 7.0 中,我通过将 MobileFirst Platform Studio 指向在本地 Web 服务器上运行的 WSDL 创建了一个 SOAP 适配器。当调用 SOAP 适配器时,它将 JSON 转换为 XML,然后当从 XML 接收到响应返回到 JSON 时,它在作为字符串返回的 JSON 中设置数字(整数、十进制)和布尔值,即在响应中用双引号将它们括起来而不是不引用它们。我没有更改 MFP Studio 自动生成的适配器中的任何内容。据我了解,在 JSON 中,布尔值和数字以及空值都没有被引用。我还有一个通过 Spring Boot 运行的非 MobileFirst Web 服务器,WebServiceGatewaySupport
用于调用相同的 SOAP 服务和@ResponseBody
注释让它自动返回 JSON,并且数字和布尔值不在返回的字符串中的双引号中。
是否期望 MobileFirst/WorklightString
在 JSON 正文中返回所有内容?如果是这样,为什么?如果没有,关于我可能需要做什么以防止这种情况发生并使其不引用数字和布尔值的任何想法?
下面是 WSDL 的相关部分和来自 Worklight SOAP 适配器的 JSON 请求/响应。
<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 响应 #1(amount
是一个 xs:decimal 包装在一个名为的 SimpleType 中money
,但它作为字符串输出到 JSON)
{
"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 响应 #2 带有布尔值的success
双引号:
{
"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 响应 #3(客户 ID 用双引号括起来,即使它被定义为 xs:int)
"customer": {
"accountNumber": "11127174",
"firstName": "JOHN",
"id": "200",
"lastName": "DOE",
"status": "None"
},
来自 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>