What You May Need to Know About Converting a JSON Interchange Format to a REST Schema

You can select to create a REST schema from a JSON interchange format sample in the Choose Type dialog of the Native Format Builder wizard, as shown in Figure 37-13. During schema generation, the wizard attempts to do the following:

  • Generate a REST schema with no namespace information

  • Consume a JSON interchange format sample with no namespace information and generate an XML with the correct namespaces

Note:

Use the JVM property soa.rest.nillable.support to turn on nillable support for SOA REST service. Values are:
  • false (default): always returns null for an empty string in the response. For example, if the payload includes data "mileage" : "", the response returns "mileage" : null
  • true: differentiates between "" and null. For example, if the payload includes data "mileage" : "", the response returns "mileage" : ""

To set soa.rest.nillable.support to true:

  • include attribute nillable="true" in the NXSD element
  • include attribute xsi:nil="true" in the XML element

Example:

When soa.rest.nillable.supported is true, the mileage element returns "" or null, matching what is provided as input ("" or null).

{
  "sampleData" : {
    "dateTime" : "2022-04-07 10:58:30",
    "mileage" : ""
  },
  "userInfo" : {
    "user" : "Davidson",
    "ctryCode" : "IN"
  }
}

When soa.rest.nillable.supported is false (default), the mileage element always returns null, regardless of what is provided as input ("" or null).

{
  "sampleData" : {
    "dateTime" : "2022-04-07 10:58:30",
    "mileage" : null
  },
  "userInfo" : {
    "user" : "Davidson",
    "ctryCode" : "IN"
  }
}

There are cases in which the conversion cannot be handled.

  • Sibling elements with duplicate names under a sequence group element cannot be converted because this translates to an object with duplicate keys in JSON, which is not valid.

  • Namespace information is retained to enable the JSON interchange format sample, shown in the following example, to be converted. This is because the underlying schema has elements and attributes from multiple namespaces.

    <schema xmlns:us="http://xmlns.oracle.com/addresses/us"
    xmlns:india="http://xmlns.oracle.com/addresses/india"
    targetNamespace="http://xmlns.oracle.com"
    xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
       <import ...>
       <element name="Person">
           <complexType>
               <choice>
                    <element ref="us:Address"/>
                    <element ref="india:Address"/>
               </choice>
           </complexType>
       </element>
    </schema>
    <schema targetNamespace="http://xmlns.oracle.com/addresses/us"
    xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
       <element name="Address">
           <complexType>
               <sequence>
                    <element name="Street" type="xsd:string"/>
                    <element name="City" type="xsd:string"/>
                    <element name="State" type="xsd:string"/>
                    <element name="ZipCode" type="xsd:integer" minOccurs="0"/>
               </sequence>
           </complexType>
       </element>
    </schema>
    <schema targetNamespace="http://xmlns.oracle.com/addresses/india"
    xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
       <element name="Address">
           <complexType>
               <sequence>
                    <element name="Street" type="xsd:string"/>
                    <element name="City" type="xsd:string"/>
                    <element name="District" type="xsd:string" minOccurs="0"/>
                    <element name="State" type="xsd:string"/>
                    <element name="PinCode" type="xsd:integer" minOccurs="0"/>
               </sequence>
           </complexType>
       </element>
    </schema>