json.Serializer.setOption

Sets an option on the JSON serializer.

Syntax

setOption(
   name STRING,
   value STRING )
  1. name is the name of a JSON serializer option of type STRING.
  2. value is a STRING.

Usage

Use this method to configure options for the JSON serializer. Each option accepts a fixed list of values, matched case insensitively. For the available options, such as datetimeSerializationMode and allowNullAsDefault, go to json.Serializer options.

An option applies to every json.Serializer call in the program until it is set again. To change an option for one call only, save its current value with getOption() and restore it afterwards.

An INTEGER value is converted to a STRING, so code written for an INTEGER parameter still works when the value is valid for the option (for a boolean option, 1 to enable it and 0 to disable it). For example, setOption("allowNullAsDefault", 1) enables the option, but setOption("allowNullAsDefault", 2) raises error -15824.

An empty or NULL option name raises error -15823. An unknown option name, or a value that is not in the list for the option, raises error -15824.

To avoid error -15824, remove any spaces before or after the name and the value, such as those in a value read from a file. For example, "1" enables a boolean option, but " 1" raises the error.

In case of error, the method throws an exception and sets the status variable. Depending on the error, a human-readable description of the problem is available in the sqlca.sqlerrm register. See Error handling in GWS calls (status).

Example: Set allowNullAsDefault

In this example, the allowNullAsDefault option is set to allow nulls. For more details, go to Deserializing JSON nulls with allowNullAsDefault.

IMPORT json
MAIN
    CALL json.Serializer.setOption("allowNullAsDefault", "1")
    #...
END MAIN