Deserializing JSON nulls with allowNullAsDefault
Use the allowNullAsDefault option to accept JSON null values during JSON to BDL deserialization.
By default, Genero Web Services JSON to Genero BDL deserialization will raise errors if the JSON
content does not match the BDL variable receiving the data. For example, you have a Genero BDL
record 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 RECORDThe 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, it is recommended that you define BDL variables 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 RECORDFor more information and examples using json_null, go to
NULLs and empty structures.