Executing the rest.extendedJSONConversion Sample
The rest.extendedJSONConversion sample includes:
- REST SOA projects (/rest-soa-projects/):
- restbt.sample.extended.json.conversion/Composites/restbt.sample.extended.json.conversion.composite (restbt.sample.extended.json.conversion/DeploymentArtifacts/restbt.sample.extended.json.conversion.daa): REST-Java (Provider) and REST-Java-REST (Client) components to demonstrate the enhancements
- com.sample.restbt.sample.extended.json.conversion: Provider and Client Java Implementations
- SoapUI projects to invoke the REST Apps (/SoapUI-projects/REST-ExtendedJSONConversion-soapui-project.xml):
Provider side (Service/Outbound/Response): XML-to-JSON Conversion of String XSD Element
Consider an XSD Element that is defined as a “string” in the Provider-side WSDL Schema (identified by the "type" attribute, which must be set to XSD string, for example 'type="xsd:string"' where "xsd" points to the XML Namespace "http://www.w3.org/2001/XMLSchema").
If the XML Response contains a non-numeric String as the value for that XSD Element (for example "teststring" or "test1234"), the JSON Response object is serialized correctly as part of the standard XML-to-JSON Conversion that is as a JSON String ("teststring" or "test1234”).
However, if the XML Response contains a purely numeric String as the value for that XSD Element (for example "1234"), then the standard XML-to-JSON Conversion converts the element to a JSON Number (for example 1234 as opposed to "1234" that is not a JSON String), which would result in an inconsistent conversion.
This holds true for other JSON types as well for example Double, Boolean, and so on. With this release, the XSD Element's (in the sample scenario, the “Value” element in Sample.wsdl) "type" attribute will be factored into the XML-to-JSON Conversion specifically for JSON Strings that is if the XSD Element is of type "string", the resultant JSON Object will be a JSON String as well and not a JSON Number.
This affects the Service-side RESPONSE. The REQUEST is not affected.
Client side (Reference/Inbound/Request): XML-to-JSON Conversion of String XSD Element
Whether or not an element is of type “string” is inferred from the Reference-side REST Resource Configuration (RRC) file, specifically from the “Request” of the “POST” method.
In the sample scenario, that would the “Request” of the “addOperation”. If you indicate via the RRC file that “Value” is a string (by use of ‘”Value”:”123”’), then with this release, the POST Request generation will honor the “string” type by sending a JSON String, even if the “Value” contains only a purely numeric value.
This affects the POST method’s REQUEST. The POST method’s RESPONSE is not affected.
This behavior is demonstrated in the “Test Scenario” section below.