Null and empty value handling in json.Serializer and util.JSON

This topic compares how json.Serializer and util.JSON handle null and empty values during JSON serialization and deserialization.

For detailed comparisons and examples, refer to the tables below dedicated to null handling for both APIs.

For more information about managing null with the json_null attribute, go to NULLs and empty structures.

Table 1. Serialization BDL to JSON
Type BDL value JSON output json.Serializer util.json
BOOLEAN NULL null ERROR 1 OK
FGL-Integer/Number NULL null ERROR 1 OK
FGL-STRING NULL null ERROR 1 OK
DATE NULL null ERROR 1 OK
DATETIME NULL null ERROR 1 OK

FGL-Object

util.JSONObject

NULL {} OK OK

FGL-Array

util.JSONArray

NULL [] OK OK

1. Requires json_null attribute or serializeNullAsDefault

Table 2. Deserialization JSON to BDL
Type JSON input Result json.Serializer util.json
BOOLEAN null NULL ERROR 2 OK
FGL-Integer null NULL ERROR 2 OK
FGL-STRING null NULL ERROR 2 OK
DATE null NULL ERROR 2 OK
DATETIME null NULL ERROR 2 OK

FGL-Object

util.JSONObject

null - ERROR 2 OK

FGL-Array

util.JSONArray

null - ERROR 2 OK

2. Requires json_null attribute or allowNullAsDefault.