@JsonSerialize
Syntax
@JsonSerialize(HJSON);
@JsonSerialize(HJSON;RETURNTYPE);
Description
This @Function serializes a JSON object or JSON array and returns its complete JSON text representation.
The generated JSON is returned in compact format without additional indentation or line breaks. Strings contained in the JSON are encoded as UTF-8.
By default, the serialized JSON is returned as a VSPECBINBUFFER. This also allows JSON structures to be serialized whose text representation exceeds the maximum size of a normal TEXT value.
Optionally, the value "A" can be specified for TEXT RETURNTYPE. In this case, the result is returned as TEXT.
If the serialized JSON representation exceeds the maximum permitted size of a TEXT value, the function returns @ERROR.
The supplied VSPECHJSON (HJS) handle remains unchanged and valid. It must be released separately with @JsonRelease when it is no longer required.
VSPECHJSON HJSON:
Handle of the JSON object or JSON array to serialize.
HJSON must contain a valid VSPECHJSON (HJS) handle.
TEXT RETURNTYPE:
Optional return type.
"A" Return as TEXT
The value is case-insensitive. If RETURNTYPE is omitted, the result is returned as VSPECBINBUFFER.
With the current implementation, any text value other than "A" also results in the default VSPECBINBUFFER return type.
As return value, the @Function returns @ERROR on failure; otherwise, it returns the serialized JSON representation as either VSPECBINBUFFER or TEXT.
Example: @JsonSerialize(HJSON);
HJSON:=@JsonCreate("Array");
@JsonAdd(HJSON;"Text1");
@JsonAdd(HJSON;"Text2");
@JsonAdd(HJSON;100);
JSONBUFFER:=@JsonSerialize(HJSON);
@JsonRelease(HJSON);
The example creates a JSON array and then serializes it using the default return type, VSPECBINBUFFER.
The buffer contains the UTF-8 encoded JSON representation:
["Text1","Text2",100.0]
Returning the result as VSPECBINBUFFER is particularly suitable for large JSON structures and for direct use in HTTP or REST requests.
Example: @JsonSerialize(HJSON;RETURNTYPE);
HJSON:=@JsonCreate;
@JsonAdd(HJSON;"Max Mustermann";"Name");
@JsonAdd(HJSON;42;"Age");
@JsonAdd(HJSON;TRUE;"Active";"B");
JSONTEXT:=@JsonSerialize(HJSON;"A");
@JsonRelease(HJSON);
The example creates a JSON object, adds three values, and then serializes the complete JSON structure as TEXT.
The content of JSONTEXT is:
{"Name":"Max Mustermann","Age":42.0,"Active":true}
The JSON handle remains unchanged by @JsonSerialize and is subsequently released with @JsonRelease.
Note : This text was machine-translated and may contain inaccuracies.
