FormatIn and FormatOut Defaults
If a Component call allows or requires RequestData input, FormatIn specifies whether RequestData is in XML or JSON format.
FormatIn can be given, inferred or defaulted-to-XML, as follows:
- If FormatIn is not given, and the first non-whitespace character is “<”, and the last non-whitespace character is “>”, FormatIn is inferred to be XML.
|
- If FormatIn is not given, and the first non-whitespace character is “{“, and the last non-whitespace character is “}”, FormatIn is inferred to be JSON. (In all SBA_ETran-formatted JSON strings, the top level is an object.)
|
- If FormatIn is given as JSON, and the first non-whitespace character is “<”, and the last non-whitespace character is “>”, the result is an error because it strongly appears to have been a mistake. (No SBA_ETran-formatted JSON string would do that.)
|
- If FormatIn is given as XML, and the first non-whitespace character is “{“, and the last non-whitespace character is “}”, the result is an error because it strongly appears to have been a mistake. (No valid XML string would do that.)
|
- If FormatIn is given and wrong-format-detection didn’t result in an error, the given value of FormatIn is used.
|
- Otherwise, FormatIn is defaulted to XML.
|
Similarly, if a Component call allows or requires ResponseData output, FormatOut specifies whether ResponseData should be in XML or JSON format.
FormatOut can be given or defaulted-to-XML, as follows:
- If the Component call also allows or requires RequestData, then FormatIn will have a value (given, inferred or defaulted), as just described. So if FormatOut is not given in that situation, it defaults to “same as FormatIn” (the end result of the FormatIn determination).
|
- If the call has only ResponseData output, FormatIn isn’t used, so FormatOut simply defaults to XML.
|
If you’re unhappy with these defaults, you might prefer to give explicit values for FormatIn and FormatOut:
- Specify FormatIn to be what you know it to be, because you created it.
|
- Specify FormatOut to be what you want it to be, because you know which format you prefer to process.
|
On the other hand, you might prefer to let FormatIn get inferred, so that you could change over between XML and JSON without having to change your web service client. It’s up to you. The SBA treats version 5.8 XML and version 5.8 JSON (for example) equivalently. Use whichever format you prefer.