Serializer options

Options of the json.Serializer class.

Table 1. Serializer option
Option Description Default Example use
allowNullAsDefault Allow NULL values to be accepted during deserialization even if the json_null="null" attribute is not explicitly specified. 0 CALL json.Serializer.setOption("allowNullAsDefault",1)

JSON to BDL deserialization options

To relax deserialization, you can set the allowNullAsDefault option to allow nulls.

By default, Genero Web Services JSON to BDL deserialization will raise errors if the JSON content does not match the BDL variable receiving the data.

For example, if the BDL variable is defined as follows:
TYPE tAddress RECORD
    street STRING,
    city STRING,
    state STRING,
    zip STRING
END RECORD

TYPE tCustomer RECORD
    id STRING,
    name STRING,
    address tAddress
END RECORD
The following JSON document will by default raise conversion errors because the "address" element is defined as "null", which does not correspond with the BDL variable:
{
  "id": "1",
  "name": "John Doe",
  "address": null
}
To avoid the conversion error, set the following option to allow nulls in your server module:
CALL json.Serializer.setOption( "allowNullAsDefault", 1 )

For more details, go to json.Serializer.setOption.

Alternatively, you can define the BDL variable with the attributes value json_null="null" to handle JSON serialization of null values.
TYPE tAddress RECORD ATTRIBUTES(json_null="null")
    street STRING,
    city STRING,
    state STRING,
    zip STRING
END RECORD
For more information, go to NULLs and empty structures