SERIALIZE-ROW( ) method

Serializes the BUFFER's current row to JSON or XML format.

Return type: LOGICAL

Applies to: Buffer object handle

Syntax

SERIALIZE-ROW ( target-format , target-type{ file | stream | stream-handle | memptr | longchar }
  [ , formatted [ , encoding [ , omit-initial-values 
  [ , omit-outer-object ] ] ] ] )
target-format
A CHARACTER expression that specifies the format of the output. Valid values are "JSON" and "XML".
target-type
A CHARACTER expression that specifies the target for the output. Valid values are "FILE", "STREAM", "STREAM-HANDLE", "MEMPTR", and "LONGCHAR".
file
A CHARACTER expression that specifies the name of a file to which the AVM writes the buffer's current row. You can specify an absolute pathname or a pathname relative to the current working directory. If a file with the specified name already exists, the AVM verifies that the file is writeable and overwrites the file.
stream
A CHARACTER expression that specifies the name of a stream. If you specify the empty string (""), the AVM writes the buffer's current row to the default unnamed output stream. For WebSpeed, write the buffer's current row to the WebSpeed-defined output stream (WEBSTREAM).

For more information about using ABL unnamed output streams, see the DEFINE STREAM statement reference entry and the chapter on alternate I/O sources in OpenEdge Development: Programming Interfaces. For more information about using WebSpeed-defined output streams, see OpenEdge Application Server: Developing WebSpeed Applications.

stream-handle
A HANDLE variable that specifies a stream object handle.
memptr
A MEMPTR variable to contain the buffer's current row in memory. If you do not specify the encoding parameter, the AVM encodes the text written to the MEMPTR as UTF-8. This method allocates the required amount of memory for the MEMPTR and sets the size of the variable. When you are finished using the MEMPTR, you must free the associated memory, by executing SET-SIZE(memptr) = 0 on the MEMPTR.
longchar
A LONGCHAR variable to contain the buffer's current row in memory.

The AVM saves the buffer's current row to the LONGCHAR variable in the code page that corresponds to the character encoding you specify in the encoding option. If you do not specify a character encoding for the LONGCHAR, the AVM saves the LONGCHAR variable in UTF-8.

If the LONGCHAR variable's code page is fixed (that is, set using the FIX-CODEPAGE statement) and the fixed code page is not equivalent to the character encoding you specify in the encoding option, the SERIALIZE-ROW( ) method generates an error and returns FALSE. The buffer's current row is not saved to the LONGCHAR.

formatted
An optional LOGICAL expression where TRUE directs the AVM to format the output in a hierarchical manner using extra white space, carriage returns, and line feeds. The default value is FALSE.

If you specify the Unknown value (?), the method uses the default value of FALSE.

encoding
An optional CHARACTER expression that specifies the name of the character encoding the AVM uses to write the output. The default encoding is "UTF-8".

When target-format is "JSON", the encoding name must specify a Unicode transformation format. Valid values are "UTF-8", "UTF-16", "UTF-16BE", "UTF-16LE", "UTF-32", "UTF-32BE", and "UTF-32LE".

When target-format is "XML", the encoding name must be an Internet Assigned Numbers Authority (IANA) name supported by the ABL XML Parser. For a list of supported IANA encodings and their corresponding ABL code pages, see the following table in the ENCODING attribute reference entry.

Note: If you specify the empty string ("") or the Unknown value (?), the AVM uses the default encoding of UTF-8.
omit-initial-values
An optional LOGICAL expression where TRUE directs the AVM to exclude temp-table fields containing their initial values from the output, and FALSE directs the AVM to include all temp-table field data in the output. The default value is FALSE. If you specify the Unknown value (?), the method uses the default value of FALSE.

When working with large ProDataSets, omitting fields containing their initial values can yield smaller output size, more efficient network transfers, and performance gains with the READ-JSON( ) and SERIALIZE-ROW( ) methods.

This behavior applies both to temp-table fields that have the default initial value for its data type, and for fields that have an initial value set with the ABL INITIAL option.

Although using the omit-initial-values option can give your application performance and resource use improvements, you must be sure that the consumers of the generated output will correctly handle it. The ABL READ-JSON( ) and READ-XML( ) methods always populate created records with initial values from the temp-table or ProDataSet definition. Other applications might not do this.

omit-outer-object
A LOGICAL expression that indicates whether the outer most object in the JSON is included. TRUE directs the AVM to remove the object on output. FALSE, indicates the objects should be left. The default is FALSE.

If you specify the Unknown value (?), the method uses the default value of FALSE.

omit-outer-object is only valid when target-format is "JSON". If omit-outer-object is TRUE when target-type is "XML", the AVM generates an error and returns FALSE.

See also

READ-JSON( ) method, READ-XML( ) method, WRITE-JSON( ) method, WRITE-XML( ) method