BDE 4.14.0 Production release
|
Provide an attribute class for specifying Datum<->JSON options.
Datum
objectsThis component provides a single, simply constrained (value-semantic) attribute class, baljsn::DatumEncoderOptions
, that is used to specify options for encoding Datum
objects in the JSON format (see baljsn::DatumUtil
).
strictTypes
: whether type-checking is performed to make sure encoded types conform to the strict set of types that JSON can represent (and can thus be decoded back to the same types of Datum
values) ([string
, double
, bool
, null
, array
, map
]).encodingStyle
: encoding style used to encode the JSON data.encodeQuotedDecimal64
: option specifying a way to encode Decimal64
values. If the encodeQuotedDecimal64
attribute in the DatumEncoderOptions
is true
(the default), the Decimal64
values will be encoded as strings, otherwise they will be encoded as numbers. Encoding a Decimal64 as a JSON numbers will frequently result it being later decoded as 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).initialIndentLevel
: Initial indent level for the topmost element.spacesPerLevel
: spaces per additional indent level.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 Datum
objects in the JSON format. This example shows how to create and populate an options object.
First, we default-construct a baljsn::DatumEncoderOptions
object:
Next, we populate that object to check strict types and encode in a pretty format using a pre-defined initial indent level and spaces per level: