BDE 4.39.x Production Release
Loading...
Searching...
No Matches
baljsn_jsonformatter.h
Go to the documentation of this file.
1/// @file baljsn_jsonformatter.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// baljsn_jsonformatter.h -*-C++-*-
8#ifndef INCLUDED_BALJSN_JSONFORMATTER
9#define INCLUDED_BALJSN_JSONFORMATTER
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup baljsn_jsonformatter baljsn_jsonformatter
15/// @brief Provide a formatter for converting `bdlat` object to `Json` analog.
16/// @addtogroup bal
17/// @{
18/// @addtogroup baljsn
19/// @{
20/// @addtogroup baljsn_jsonformatter
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#baljsn_jsonformatter-purpose"> Purpose</a>
25/// * <a href="#baljsn_jsonformatter-classes"> Classes </a>
26/// * <a href="#baljsn_jsonformatter-description"> Description </a>
27/// * <a href="#baljsn_jsonformatter-assembling-an-array"> Assembling an Array </a>
28/// * <a href="#baljsn_jsonformatter-assembling-an-object"> Assembling an Object </a>
29/// * <a href="#baljsn_jsonformatter-usage"> Usage </a>
30/// * <a href="#baljsn_jsonformatter-basic-syntax"> Basic Syntax </a>
31///
32/// # Purpose {#baljsn_jsonformatter-purpose}
33/// Provide a formatter for converting `bdlat` object to `Json` analog.
34///
35/// # Classes {#baljsn_jsonformatter-classes}
36///
37/// - baljsn::JsonFormatter: mechanism for setting the value of a `bdljsn::Json`
38///
39/// @see baljsn_encoder, baljsn_formatter, bdljsn_json
40///
41/// # Description {#baljsn_jsonformatter-description}
42/// This component provides a stateful mechanism,
43/// `baljsn::JsonFormatter`, that sets the value of a `bdljsn::Json` object
44/// according to the invocations of the formatter`s various manipulator methods.
45///
46/// The target `bdljsn::Json` object can be set to either a JSON scalar
47/// (i.e., `isNull()`, `isBoolean()`, `isNumber()`, `isString()`), or an a JSON
48/// array (`isArray()`), or a JSON object (`isObject()`). Recall that JSON
49/// arrays consist of a list of elements that can each be either a scalar or an
50/// object or an array. Also recall that each object is a name/value pair
51/// where the value portion can be either a scalar or an object or an array.
52///
53/// The `bdljsn::Json` object must be built up in top-down order. The proper
54/// order of manipulator calls must, in effect, follow a pre-order tranversal
55/// of the object being created. For details of adding arrays and adding
56/// objects see @ref baljsn_jsonformatter-assembling-an-array and [](@ref baljsn_jsonformatter-assembling-an-object) .
57/// Calling these mainipulators in other orders can cause undefined behavior.
58///
59/// The provided manipulators do *not* allow for any editing once a value has
60/// been set. Once a `bdljsn::Json` target object has been given a scalar value
61/// or started as an array or as an object, any attempt to undo that action
62/// results in undefined behavior.
63///
64/// Note that two of the manipulators, `addArrayElementSeparators` and
65/// `nestingDepth`, are not relevant to assembling `bdljsn::Json` objects
66/// and are defined as "no-ops". These manipulators are provided so
67/// `baljsn::JsonFormatter` can be used in the same context as
68/// `baljsn::Formatter`.
69///
70/// ## Assembling an Array {#baljsn_jsonformatter-assembling-an-array}
71///
72///
73/// A `bdljsn::Json` object of array type is assembled using the following
74/// series of manipulator calls.
75///
76/// * `openArray` starts an array (the "current" array).
77///
78/// * `putValue`/`putNullValue` calls each adds to the current array an
79/// element having the appropriate scalar type.
80///
81/// * `openObject` adds an array element that is a name/value pair (an Json
82/// object).
83///
84/// * `openArray` starts a new array within the current array. Subsequent
85/// operations assemble this new array until `closeArray` is called.
86///
87/// * Repeat the addition of new elements to the current array by calls
88/// to `putValue`/`putNullValue`/`openObject`/`openArray` as appropriate.
89///
90/// * `closeArray` indicates that there are no more elements to be added
91/// to the current array.
92///
93/// ## Assembling an Object {#baljsn_jsonformatter-assembling-an-object}
94///
95///
96/// A `bdljsn::Json` object of object type (i.e., a name/value) is assembled
97/// using the following series of manipulator calls in the order shown
98/// below.
99///
100/// * `openObject` starts a new object (the "current" object).
101///
102/// * `openMember` starts a new member of the object and provides the name
103/// portion of the name/value pair.
104///
105/// * `putValue`/`putNullValue` sets the provided value as the "value" portion
106/// of the name/value pair.
107///
108/// * `openArray` starts an array as the value portion of the name/value pair.
109///
110/// * `openObject` starts a new object as the value portion of the
111/// name/value pair. Subsequent calls define this object until `closeMember`
112/// is called.
113///
114/// * `closeMember` indicates that the member has been completed.
115///
116/// * Repeat the addition of new members as appropriate.
117///
118/// * `closeObject` indicates that there are no more members to be added to the
119/// current object.
120///
121/// ## Usage {#baljsn_jsonformatter-usage}
122///
123///
124/// This section illustrates intended use of this component.
125///
126/// ### Basic Syntax {#baljsn_jsonformatter-basic-syntax}
127///
128///
129/// Let us say that we have a JSON document describing some (hypothetical)
130/// employee data that we wish to convert to a `bdljsn::Json` object so we can
131/// examine and manipulate that data programmatically.
132///
133/// @code
134/// { "name" : "Bob",
135/// "homeAddress" :
136/// { "street" : "Lexington Ave",
137/// "city" : "New York City",
138/// "state" : "New York"
139/// },
140/// "age" : 21
141/// }
142/// @endcode
143/// First, we create a `bdljsn::Json` object and directly use the manipulators
144/// provided by that class.
145/// @code
146/// bdljsn::Json json1;
147/// json1.makeObject();
148/// json1["name"];
149/// json1["homeAddress"];
150/// json1["age"];
151///
152/// bdljsn::Json address;
153/// address.makeObject();
154/// address["street"] = "Lexington Ave";
155/// address["city"] = "New York City";
156/// address["state"] = "New York";
157///
158/// json1["name"] = "Bob";
159/// json1["homeAddress"] = address;
160/// json1["age"] = 21;
161/// @endcode
162/// Notice that, since we have the freedom to do so, we choose to assemble
163/// `json1` in a breadth-first order:
164///
165/// 1. First we enter the top-level members by name, `"name"`,
166/// `"homeAddress"`, and `"age"`.
167/// 2. Then we assign values to each of those members. In the case of
168/// `"homeAddress"`, we use a separately assembled object.
169///
170/// Now, we confirm that we can also assemble an equivalent object using
171/// the `baljsn::JsonFormatter` mechanism.
172/// @code
173/// bdljsn::Json json2;
174/// baljsn::JsonFormatter formatter(&json2);
175///
176/// formatter.openObject();
177///
178/// formatter.openMember("name");
179/// formatter.putValue("Bob");
180/// formatter.closeMember();
181///
182/// formatter.openMember("homeAddress");
183/// formatter.openObject(); // The "value" of the "homeAddress" member.
184///
185/// formatter.openMember("street");
186/// formatter.putValue("Lexington Ave");
187/// formatter.closeMember();
188///
189/// formatter.openMember("city");
190/// formatter.putValue("New York City");
191/// formatter.closeMember();
192///
193/// formatter.openMember("state");
194/// formatter.putValue("New York");
195/// formatter.closeMember();
196///
197/// formatter.closeObject();
198/// formatter.closeMember(); // "homeAddress"
199///
200/// formatter.openMember("age");
201/// formatter.putValue(21);
202/// formatter.closeMember();
203///
204/// formatter.closeObject();
205/// @endcode
206/// Finally, we confirm that the two assembled objects are equal.
207///
208/// @code
209/// assert(json1 == json2);
210/// @endcode
211/// @}
212/** @} */
213/** @} */
214
215/** @addtogroup bal
216 * @{
217 */
218/** @addtogroup baljsn
219 * @{
220 */
221/** @addtogroup baljsn_jsonformatter
222 * @{
223 */
224
225#include <balscm_version.h>
226
227#include <baljsn_printutil.h>
228
229#include <bdljsn_json.h>
230#include <bdljsn_jsonnumber.h>
231
232#include <bdlt_date.h>
233#include <bdlt_datetime.h>
234#include <bdlt_datetimetz.h>
235#include <bdlt_datetz.h>
236#include <bdlt_time.h>
237#include <bdlt_timetz.h>
238#include <bdlt_iso8601util.h>
240
241#include <bdlb_float.h>
242
243#include <bslma_aatypeutil.h>
244#include <bslma_allocatorutil.h>
245#include <bslma_bslallocator.h>
246
248
249#include <bsla_fallthrough.h>
250#include <bsla_maybeunused.h>
251
252#include <bsls_assert.h>
253
254#include <bsl_cstddef.h> // `bsl::size_t`
255#include <bsl_limits.h> // `bsl::numeric_limits`
256#include <bsl_ostream.h>
257#include <bsl_sstream.h> // `bsl::ostringstream`
258#include <bsl_stack.h>
259#include <bsl_string.h>
260#include <bsl_string_view.h>
261#include <bsl_utility.h> // `bsl::pair`
262
263
264namespace baljsn {
265
266class EncoderOptions;
267
268 // =========================
269 // class JsonFormatter_State
270 // =========================
271
272/// This `struct` defines an enumeration of the internal states that a
273/// a `JsonFormatter` can reach as it processes user requests to `openArray`,
274/// `putValue`(s), `closeArray`, etc. These states influence the formatter
275/// and, in some build modes, detect errors in call sequences.
276///
277/// See @ref baljsn_jsonformatter
279
280 // TYPES
288
289 // CLASS METHODS
290 static bsl::ostream& print(bsl::ostream& stream,
291 Enum value,
292 int level = 0,
293 int spacesPerLevel = 4);
294 static const char *toAscii(Enum value);
295};
296
297bsl::ostream& operator<<(bsl::ostream& stream,
299
300 // -------------------------
301 // class JsonFormatter_State
302 // -------------------------
303
304// FREE OPERATORS
305inline
306bsl::ostream& operator<<(bsl::ostream& stream,
308{
309 return JsonFormatter_State::print(stream, value, 0, -1);
310}
311
312 // ========================
313 // class JsonFormatter_Util
314 // ========================
315
317
318#ifdef BSLS_ASSERT_SAFE_IS_ACTIVE
319 template <class TYPE>
320 static int expectedReturnPutValue(const TYPE& value,
321 const EncoderOptions *options);
322
323 static int expectedReturnPutValue(const char *value,
324 const EncoderOptions *options);
325
326 template <class TYPE>
327 static int expectedReturnFloatingPoint(const TYPE& value,
328 const EncoderOptions *options);
329#endif
330
331 template <class TYPE>
332 static int setFloatingPointToJson(bdljsn::Json *json,
333 const TYPE& value,
334 const EncoderOptions *options);
335
336 template <class TYPE>
337 static int setTemporalValueToJson(bdljsn::Json *json,
338 const TYPE& value,
339 const EncoderOptions *options);
340
341 template <class TYPE>
342 static int valueAsJson(bdljsn::Json *json,
343 const TYPE& value,
344 const EncoderOptions *options);
345
346 static int valueAsJson(bdljsn::Json *json,
347 const char *value,
348 const EncoderOptions *options);
349
350};
351
352 // ===================
353 // class JsonFormatter
354 // ===================
355
356/// This class implements a formatter mechanism that assembles a (potentially
357/// complicated) `bdljsn::Json` object according to the invocations of the
358/// formatter's manipulators.
359///
360/// See @ref baljsn_jsonformatter
362
363 // PRIVATE TYPES
364
367
368 public:
369
370 // TYPES
371
373
374 // DATA
375
378
379 // PRIVATE MANIPULATORS
380
381 /// Print the internal stack of `Status` objects to standard output in lifo
382 /// order. Each line of output consists of:
383 ///
384 /// * The stack depth
385 /// * The `bdljsn::JsonType` of the referenced `bdljsn::Json` object.
386 /// * The internal state, a `JsonFormatter_State::Enum` value.
387 ///
388 ///
389 /// \note Note that this function is provided for debugging only.
390 void dumpStack(); // Restores stack state to state when called.
391
392 public:
393 // CREATORS
394
395 /// Create a `JsonFormatter` object that modifies the specified `json`
396 /// object in accordance with subsequent calls the formatter manipulators.
397 /// Optionally specify an `allocator` (e.g., the address of a
398 /// `bslma::Allocator` object) to supply memory; otherwise, the default allocator is used.
399 ///
400 /// \pre The behavior is undefined unless `json->isNull()`.
402 const allocator_type& allocator = allocator_type());
403
404 /// Destroy this object.
405 ~JsonFormatter() = default;
406
407 // MANIPULATORS
408
409 /// Create a new object (set of name/value pairs also know as "members").
410 /// Note subsequently created members will land in this object until
411 /// `closeObject` is called.
413
414 /// Indicate that there are no more members to be added to the current
415 /// object.
417
418 /// Create a new array. Subsequently created elements will land in this
419 /// array (in order of creation) until `closeArray` is called. The
420 /// elements can be created by
421 /// `putValue`/`putNullValue`/`openObject`/`openArray`. The specified
422 /// `formatAsEmptyArray` is ignored; arrays are unconditionally formatted.
423 void openArray(bool formatAsEmptyArray = false);
424
425 /// Indicate that there are no more elements to be added to the current
426 /// array. The specified `formatAsEmptyArray` is ignored; arrays are
427 /// unconditionally formatted.
428 void closeArray(bool formatAsEmptyArray = false);
429
430 /// Create a new object member having the specified `name`. Return 0 on
431 /// success and a non-zero value otherwise. An error is returned if `name`
432 /// contains a non-UTF8 character.
433 int openMember(const bsl::string_view& name);
434
435 /// Set the value of the current array element or object value -- depending
436 /// on the context -- to `bdljsn::JsonNull`. Return 0 on success and a
437 /// non-zero value otherwise. An error is returned when `putNullValue`
438 /// is called in an unexpected context.
440
441 /// Set the value of the current scalar, array element, or object value --
442 /// depending on the context -- to the specified `value` of (template
443 /// parameter) `TYPE`. The specified `options` is ignored except:
444 /// * `encodeInfAndNaNAsStrings` when `TYPE` is a floating point type.
445 /// * `datetimeFractionalSecondPrecision` when `TYPE` features a
446 /// datetime or time attribute.
447 /// Return 0 on success and a non-zero value otherwise. Errors are
448 /// returned if `value` is disallowed for `bdljsn::Json` objects:
449 /// * `value` is a string type and contains a non-UTF8 character.
450 /// * `value` is a floating point type, is INF or NaN, and
451 /// `false == encodeInfAndNanAsStrings`.
452 template <class TYPE>
453 int putValue(const TYPE& value, const EncoderOptions *options = 0);
454
455 /// Indicate that there are no more members to be added to the current
456 /// object.
458
459 /// No-op.
461
462 // ACCESSORS
463
464 /// No-op. Return 0.
465 int nestingDepth() const;
466
467 // Aspects
468
469 /// Return the allocator used by this object to supply memory.
470 ///
471 /// \note Note that if no allocator was supplied at construction the default
472 /// allocator in effect at construction is used.
474};
475
476// ============================================================================
477// INLINE DEFINITIONS
478// ============================================================================
479
480 // ------------------------
481 // class JsonFormatter_Util
482 // ------------------------
483
484#ifdef BSLS_ASSERT_SAFE_IS_ACTIVE
485template <class TYPE>
486int JsonFormatter_Util::expectedReturnPutValue(BSLA_MAYBE_UNUSED
487 const TYPE& value,
489 const EncoderOptions *options)
490{
491 return 0;
492}
493
494template <class TYPE>
495inline
496int JsonFormatter_Util::expectedReturnFloatingPoint(
497 const TYPE& value,
498 const EncoderOptions *options)
499{
500 switch(bdlb::Float::classify(value)) {
502 case bdlb::Float::k_NAN: {
503 return options && options->encodeInfAndNaNAsStrings() ? 0 : -1;
504 // RETURN
505 } break;
506 default: {
507 return 0; // RETURN
508 } break;
509 }
510}
511
512template <>
513inline
514int JsonFormatter_Util::expectedReturnPutValue(const float& value,
515 const EncoderOptions *options)
516{
517 return expectedReturnFloatingPoint(value, options);
518}
519
520template <>
521inline
522int JsonFormatter_Util::expectedReturnPutValue(const double& value,
523 const EncoderOptions *options)
524{
525 return expectedReturnFloatingPoint(value, options);
526}
527
528inline
529int JsonFormatter_Util::expectedReturnPutValue(const char *value,
531 const EncoderOptions *options)
532{
533 BSLS_ASSERT(value);
534 return bdlde::Utf8Util::isValid(value) ? 0 : -1;
535}
536
537template <>
538inline
539int JsonFormatter_Util::expectedReturnPutValue(const bsl::string& value,
541 const EncoderOptions *options)
542{
543 return bdlde::Utf8Util::isValid(value.data(), value.length()) ? 0 : -1;
544}
545#endif // BSLS_ASSERT_SAFE_IS_ACTIVE
546
547template <class TYPE>
549 const TYPE& value,
550 const EncoderOptions *options)
551{
552 BSLS_ASSERT_SAFE(json);
553
554 bdlb::Float::FineClassification classification =
556 switch (classification) {
560 case bdlb::Float::k_SNAN: {
561 if (options && options->encodeInfAndNaNAsStrings()) {
562 const char *asString = PrintUtil::floatingPointSpecialAsString(
563 classification);
564 BSLS_ASSERT_SAFE(asString);
565 json->makeString(asString);
566 }
567 else {
568 return -1; // RETURN
569 }
570 } break;
579 *json = value;
580 } break;
581 default: {
582 BSLS_ASSERT_INVOKE_NORETURN("Should not reach.");
583 } break;
584 }
585 return 0;
586}
587
588template <class TYPE>
590 const TYPE& value,
591 const EncoderOptions *options)
592{
593 BSLS_ASSERT_SAFE(json);
594
596 if (options) {
599 }
600 else {
602 }
603
604 const bsl::size_t bufferSize = bdlt::Iso8601Util::k_MAX_STRLEN + 1;
605 char buffer[bufferSize];
606 bdlt::Iso8601Util::generate(buffer, bufferSize, value, config);
607 json->makeString(buffer);
608 return 0;
609}
610
611template <class TYPE>
613 const TYPE& value,
615 const EncoderOptions *options)
616{
617 BSLS_ASSERT_SAFE(json);
618 *json = value;
619 return 0;
620}
621
622inline
624 const char *value,
626 const EncoderOptions *options)
627{
628 BSLS_ASSERT_SAFE(json);
629 BSLS_ASSERT_SAFE(value);
630
631 if (bdlde::Utf8Util::isValid(value)) {
632 *json = value;
633 return 0;
634 } else {
635 return -1;
636 }
637}
638
639template <>
640inline
642 const bsl::string& value,
644 const EncoderOptions *options)
645{
646 BSLS_ASSERT_SAFE(json);
647 if (bdlde::Utf8Util::isValid(value.data(), value.length())) {
648 *json = value;
649 return 0;
650 } else {
651 return -1;
652 }
653}
654
655template <>
656inline
658 const bdlt::Date& value,
659 const EncoderOptions *options)
660{
661 BSLS_ASSERT_SAFE(json);
662 return setTemporalValueToJson(json, value, options);
663}
664
665template <>
666inline
668 const bdlt::Time& value,
669 const EncoderOptions *options)
670{
671 BSLS_ASSERT_SAFE(json);
672 return setTemporalValueToJson(json, value, options);
673}
674
675template <>
676inline
678 const bdlt::Datetime& value,
679 const EncoderOptions *options)
680{
681 BSLS_ASSERT_SAFE(json);
682 return setTemporalValueToJson(json, value, options);
683}
684
685template <>
686inline
688 const bdlt::DateTz& value,
689 const EncoderOptions *options)
690{
691 BSLS_ASSERT_SAFE(json);
692 return setTemporalValueToJson(json, value, options);
693}
694
695template <>
696inline
698 const bdlt::TimeTz& value,
699 const EncoderOptions *options)
700{
701 BSLS_ASSERT_SAFE(json);
702 return setTemporalValueToJson(json, value, options);
703}
704
705template <>
706inline
708 const bdlt::DatetimeTz& value,
709 const EncoderOptions *options)
710{
711 BSLS_ASSERT_SAFE(json);
712 return setTemporalValueToJson(json, value, options);
713}
714
715template <>
716inline
718 const float& value,
719 const EncoderOptions *options)
720{
721 BSLS_ASSERT_SAFE(json);
722 return setFloatingPointToJson(json, value, options);
723}
724
725template <>
726inline
728 const double& value,
729 const EncoderOptions *options)
730{
731 BSLS_ASSERT_SAFE(json);
732 return setFloatingPointToJson(json, value, options);
733}
734
735template <>
736inline
738 const bdldfp::Decimal64& value,
740 const EncoderOptions *options)
741{
742
743 BSLS_ASSERT_SAFE(json);
744
745 typedef bdldfp::Decimal64 DEC64;
746
747 static const DEC64 INF_POS = bsl::numeric_limits<DEC64>::infinity();
748 static const DEC64 INF_NEG = -INF_POS;
749
750 switch (bdldfp::DecimalUtil::classify(value)) {
751 case FP_NAN: {
752 json->makeString("nan");
753 } break;
754 case FP_INFINITE: {
755 if (INF_POS == value) { json->makeString("+inf");
756 } else if (INF_NEG == value) { json->makeString("-inf");
757 } else { BSLS_ASSERT_OPT(false && "reachable");
758 }
759 } break;
760 default: {
761 json->makeNumber(bdljsn::JsonNumber(value));
762 } break;
763 }
764 return 0;
765}
766 // -------------------
767 // class JsonFormatter
768 // -------------------
769
770// CREATORS
771
772inline
774 const allocator_type& allocator)
775: d_allocator(allocator)
776, d_stack(bslma::AllocatorUtil::adapt(allocator))
777{
778 BSLS_ASSERT(json);
779 BSLS_ASSERT(json->isNull());
780
781 d_stack.push(bsl::make_pair(json, State::e_AT_START));
782}
783
784// MANIPULATORS
785
786template <class TYPE>
787int JsonFormatter::putValue(const TYPE& value, const EncoderOptions *options)
788{
789 BSLS_ASSERT_OPT(0 < d_stack.size());
790
791 bdljsn::Json& top = *d_stack.top().first;
792 State::Enum state = d_stack.top().second;
793
794#ifdef BSLS_ASSERT_SAFE_IS_ACTIVE
795 const int expRc = JsonFormatter_Util::expectedReturnPutValue(value,
796 options);
797#endif
798 BSLA_MAYBE_UNUSED int rc;
799
800 switch (state) {
801 case State::e_AT_START: {
802 BSLS_ASSERT_SAFE(1 == d_stack.size());
804 rc = JsonFormatter_Util::valueAsJson(&top, value, options);
805 BSLS_ASSERT_SAFE(expRc == rc);
806 d_stack.pop();
807 } break;
808 case State::e_IN_ARRAY: {
813 value,
814 options);
815 BSLS_ASSERT_SAFE(expRc == rc);
816 } break;
819 rc = JsonFormatter_Util::valueAsJson(&top, value, options);
820 BSLS_ASSERT_SAFE(expRc == rc);
822 BSLS_ASSERT_SAFE(!top.isNull()); // `null` is set in `putNullValue`,
823 // not here in `putValue`.
824 } break;
825 default : {
826 BSLS_ASSERT_INVOKE_NORETURN(0); // Should not reach.
827 } break;
828 }
829
830 return rc;
831}
832
833inline
837
838// ACCESSORS
839inline
841{
842 return 0;
843}
844
845inline
850
851} // close package namespace
852
853
854#endif
855
856// ----------------------------------------------------------------------------
857// Copyright 2025 Bloomberg Finance L.P.
858//
859// Licensed under the Apache License, Version 2.0 (the "License");
860// you may not use this file except in compliance with the License.
861// You may obtain a copy of the License at
862//
863// http://www.apache.org/licenses/LICENSE-2.0
864//
865// Unless required by applicable law or agreed to in writing, software
866// distributed under the License is distributed on an "AS IS" BASIS,
867// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
868// See the License for the specific language governing permissions and
869// limitations under the License.
870// ----------------------------- END-OF-FILE ----------------------------------
871
872/** @} */
873/** @} */
874/** @} */
Definition baljsn_encoderoptions.h:290
bool encodeInfAndNaNAsStrings() const
Definition baljsn_encoderoptions.h:1061
int datetimeFractionalSecondPrecision() const
Definition baljsn_encoderoptions.h:1067
Definition baljsn_jsonformatter.h:361
allocator_type d_allocator
Definition baljsn_jsonformatter.h:376
void openArray(bool formatAsEmptyArray=false)
void addArrayElementSeparator()
No-op.
Definition baljsn_jsonformatter.h:834
void closeArray(bool formatAsEmptyArray=false)
allocator_type get_allocator() const
Definition baljsn_jsonformatter.h:846
int nestingDepth() const
No-op. Return 0.
Definition baljsn_jsonformatter.h:840
int openMember(const bsl::string_view &name)
bsl::allocator< char > allocator_type
Definition baljsn_jsonformatter.h:372
JsonFormatter(bdljsn::Json *json, const allocator_type &allocator=allocator_type())
Definition baljsn_jsonformatter.h:773
~JsonFormatter()=default
Destroy this object.
bsl::stack< Status > d_stack
Definition baljsn_jsonformatter.h:377
int putValue(const TYPE &value, const EncoderOptions *options=0)
Definition baljsn_jsonformatter.h:787
Definition bdldfp_decimal.h:1890
JsonArray & pushBack(const Json &json)
Definition bdljsn_json.h:3561
Json & back()
Definition bdljsn_json.h:3446
Definition bdljsn_jsonnumber.h:412
Definition bdljsn_json.h:1461
JsonNumber & makeNumber()
Definition bdljsn_json.h:4511
bool isArray() const
Definition bdljsn_json.h:5058
void makeString(const char *string)
Definition bdljsn_json.h:4551
JsonArray & theArray()
Definition bdljsn_json.h:5094
bool isNull() const
Definition bdljsn_json.h:5070
Definition bdlt_datetz.h:161
Definition bdlt_date.h:294
Definition bdlt_datetimetz.h:308
Definition bdlt_datetime.h:330
Definition bdlt_iso8601utilconfiguration.h:224
void setFractionalSecondPrecision(int value)
Definition bdlt_timetz.h:190
Definition bdlt_time.h:195
Definition bslma_bslallocator.h:588
Definition bslstl_stringview.h:471
Definition bslstl_string.h:1252
size_type length() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_string.h:7301
CHAR_TYPE * data() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_string.h:7177
Definition bslstl_pair.h:1280
Definition bslstl_stack.h:412
#define BSLA_FALLTHROUGH
Definition bsla_fallthrough.h:188
#define BSLA_MAYBE_UNUSED
Definition bsla_maybeunused.h:239
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1917
#define BSLS_ASSERT_OPT(X)
Definition bsls_assert.h:2045
#define BSLS_ASSERT_INVOKE_NORETURN(X)
Definition bsls_assert.h:2101
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition baljsn_convertfromjsonoptions.h:112
bsl::ostream & operator<<(bsl::ostream &stream, const DatumDecoderOptions &rhs)
Definition baljsn_encoder_testtypes.h:76
Definition baljsn_jsonformatter.h:278
static bsl::ostream & print(bsl::ostream &stream, Enum value, int level=0, int spacesPerLevel=4)
static const char * toAscii(Enum value)
Enum
Definition baljsn_jsonformatter.h:281
@ e_IN_OBJECT_EXPECTING_MEMBER_NAME
Definition baljsn_jsonformatter.h:284
@ e_IN_OBJECT_EXPECTING_MEMBER_VALUE
Definition baljsn_jsonformatter.h:285
@ e_IN_ARRAY
Definition baljsn_jsonformatter.h:283
@ e_IN_OBJECT_EXPECTING_MEMBER_CLOSE
Definition baljsn_jsonformatter.h:286
@ e_AT_START
Definition baljsn_jsonformatter.h:282
Definition baljsn_jsonformatter.h:316
static int valueAsJson(bdljsn::Json *json, const TYPE &value, const EncoderOptions *options)
static int valueAsJson(bdljsn::Json *json, const char *value, const EncoderOptions *options)
static int setFloatingPointToJson(bdljsn::Json *json, const TYPE &value, const EncoderOptions *options)
Definition baljsn_jsonformatter.h:548
static int setTemporalValueToJson(bdljsn::Json *json, const TYPE &value, const EncoderOptions *options)
Definition baljsn_jsonformatter.h:589
static const char * floatingPointSpecialAsString(bdlb::Float::FineClassification classification)
Definition baljsn_printutil.h:357
@ k_NAN
Definition bdlb_float.h:230
@ k_INFINITE
Definition bdlb_float.h:229
static FineClassification classifyFine(float number)
FineClassification
Definition bdlb_float.h:244
@ k_NEGATIVE_NORMAL
Definition bdlb_float.h:253
@ k_POSITIVE_NORMAL
Definition bdlb_float.h:252
@ k_NEGATIVE
Definition bdlb_float.h:245
@ k_SNAN
Definition bdlb_float.h:251
@ k_POSITIVE_SUBNORMAL
Definition bdlb_float.h:254
@ k_NEGATIVE_ZERO
Definition bdlb_float.h:257
@ k_NEGATIVE_SUBNORMAL
Definition bdlb_float.h:255
@ k_POSITIVE_ZERO
Definition bdlb_float.h:256
@ k_NEGATIVE_INFINITY
Definition bdlb_float.h:249
@ k_SIGNALING
Definition bdlb_float.h:246
@ k_QNAN
Definition bdlb_float.h:250
@ k_POSITIVE_INFINITY
Definition bdlb_float.h:248
static Classification classify(float number)
static bool isValid(const char *string)
Definition bdlde_utf8util.h:1069
static int classify(Decimal32 x)
@ k_MAX_STRLEN
Definition bdlt_iso8601util.h:779
static int generate(char *buffer, ssize_t bufferLength, const bsls::TimeInterval &object)
Definition bdlt_iso8601util.h:2017
static bsl::enable_if<!IsDerivedFromBslAllocator< t_ALLOC >::value, t_ALLOC >::type adapt(const t_ALLOC &from)
Definition bslma_allocatorutil.h:871