BDE 4.14.0 Production release
|
Provide an attribute class for specifying JSON encoding options.
This component provides a single, simply constrained (value-semantic) attribute class, baljsn::EncoderOptions
, that is used to specify options for encoding objects in the JSON format.
encodingStyle
: encoding style used to encode the JSON data.initialIndentLevel
: Initial indent level for the topmost element.spacesPerLevel
: spaces per additional indent level.encodeEmptyArrays
: option specifying if empty arrays should be encoded (empty arrays occurring as selections of choices are always encoded).encodeNullElements
: option specifying if null elements should be encoded.encodeInfAndNaNAsStrings
: JSON does not provide a way to encode these values as they are not numbers. This option provides a way to encode these values. Although the resulting output is a valid JSON document, decoders expecting floating point numbers to be encoded only as numbers will fail to decode. Users of this option must therefore exercise caution and ensure that if this option is used then the parser decoding the generated JSON can handle doubles as strings.encodeQuotedDecimal64
: option specifying a way to encode Decimal64
values. If the encodeQuotedDecimal64
attribute value is true
(the default), the Decimal64
values will be encoded quoted, and otherwise they will be encoded as numbers. Encoding a Decimal64 as a JSON number will frequently result in it being later decoded as a binary floating point number, and in the process losing digits of precision that were the point of using the Decimal64 type in the first place. Care should be taken when setting this option to false
(though it may be useful when communicating with endpoints that are known to correctly handle high precision JSON numbers).datetimeFractionalSecondPrecision
: option specifying the number of decimal places used for seconds when encoding Datetime
and DatetimeTz
.maxFloatPrecision
: [DEPRECATED] option specifying the maximum number of decimal places used to encode each float
value. When 0 (the default value) the encoder will use the minimum that is necessary to restore the binary value into a float
. We recommend against setting this option: the option was provided prior to the current default behavior (of choosing the shortest presentation that can be restored to the original value) being available.maxDoublePrecision
: [DEPRECATED] option specifying the maximum number of decimal places used to encode each double
value. When 0 (the default value) the encoder will use the minimum that is necessary to restore the binary value into a double
. We recommend against setting this option: the option was provided prior to the current default behavior (of choosing the shortest presentation that can be restored to the original value) being available.This file was generated from a script and was subsequently modified to add documentation and to make other changes. The steps to generate and update this file can be found in the doc/generating_codec_options.txt
file.
This section illustrates intended use of this component.
This component is designed to be used at a higher level to set the options for encoding objects in the JSON format. This example shows how to create and populate an options object.
First, we default-construct a baljsn::EncoderOptions
object:
Next, we populate that object to encode in a prett format using a pre-defined initial indent level and spaces per level: