json_null
handling
This section focuses on the key differences in handling null or empty values between
json.Serializer
and util.json
when the json_null
attribute is used.
The handling of the json_null
attribute and schema-related features differs
significantly between util.json
and json.Serializer
:
-
util.json
- The
json_null
attribute only affects serialization (BDL to JSON). - At the root level, a missing value is implicitly treated as
null
. - Ignores schema-related attributes such as
JSONRequired
at runtime.
- The
-
json.Serializer
- The
json_null
attribute affects both serialization (BDL to JSON) and deserialization (JSON to BDL). - At the root level, a missing value is considered an error, even if
json_null="undefined"
is set. - Performs field presence validation and handles default values during deserialization.
- Processes and enforces schema-related attributes such as
JSONRequired
.
- The
For more information about managing null with the json_null
attribute, go to
NULLs and empty structures.
Recommended practice
json.Serializer
:- Avoid relying on
json_null="undefined"
at the root level. - If the root value may be omitted, wrap the primitive type inside a
RECORD
to ensure proper control and prevent deserialization errors.
Value is NULL | Target type | json.Serializer | util.JSON | Notes |
---|---|---|---|---|
(default) | ||||
Primitive type | Omitted | Omitted | if root |
|
|
{} / [] |
{} / [] |
if root |
|
json_null="null" |
||||
Primitive type | null |
null |
||
|
null |
null |
||
json_null="undefined" |
||||
Primitive type | Omitted | Omitted | undefined at root is treated as
null
|
|
|
Omitted | Omitted | undefined at root is treated as
null
|
|
JSONRequired |
||||
Primitive type | ERROR | Omitted | util.JSON ignores attribute JSONRequired |
|
|
{} / [] |
{} / [] |
util.JSON ignores attribute JSONRequired |
|
JSONRequired + json_null="null" |
||||
Primitive type | null |
null |
util.JSON ignores attribute JSONRequired |
|
|
null |
null |
util.JSON ignores attribute JSONRequired |
|
JSONRequired + |
||||
Primitive type | ERROR | null |
util.JSON ignores attribute JSONRequired |
|
|
ERROR | null |
util.JSON ignores attribute JSONRequired |
Incoming Value | Target type | Attribute | json.Serializer | util.JSON | Notes |
---|---|---|---|---|---|
Omitted | |||||
Primitive type | OK | OK | ERROR if root | ||
|
OK | OK | ERROR if root | ||
null |
|||||
Primitive type | ERROR | OK | |||
|
ERROR | OK | |||
Omitted | |||||
Primitive type | json_null="null" |
OK | OK | ERROR if root | |
|
json_null="null"
|
OK | OK | ERROR if root | |
{} / [] |
|
OK | OK | ||
null |
|||||
Primitive type | json_null="null" |
OK | OK | ||
|
json_null="null" |
OK | OK | ||
Omitted | |||||
Primitive type | json_null = "undefined" |
OK | OK | ERROR if root | |
|
json_null = "undefined"
|
OK | OK | ERROR if root | |
Omitted | |||||
Primitive type | JSONRequired |
ERROR | OK | util.JSON ignores attribute JSONRequired |
|
|
JSONRequired
|
ERROR | OK | util.JSON ignores attribute JSONRequired |
|
null |
|||||
Primitive type | JSONRequired |
ERROR | OK | ||
|
JSONRequired
|
ERROR | OK | ||
Omitted | |||||
Primitive type | JSONRequired + json_null="null" |
OK | OK | ||
|
JSONRequired + json_null="null"
|
OK | OK | ||
Omitted | |||||
Primitive type | JSONRequired + json_null="undefined" |
ERROR | OK | json.Serializer : "undefined" should be treated as
json_null="null" at the root level |
|
|
JSONRequired + json_null="undefined"
|
ERROR | OK | json.Serializer : "undefined" should be treated as json_null="null"
at the root level |