|
BDE 4.39.x Production Release
|
#include <baljsn_jsonconverter.h>
This class provides a mechanism for copying the constituent values of certain bdlat-compatible objects to bdljsn::Json objects, and vice versa. In each case, the resulting object is a different representation of the data in the original. This conversion is analogous to the encoding and decoding operations provided elsewhere in this package; however, the convert methods here avoid the creation of any textual representation of the data.
The bdlat objects must meet the requirements of a sequence, choice, or array as defined in bdlat_sequencefunctions , bdlat_choicefunctions , and bdlat_arrayfunctions components, respectively.
Public Types | |
| typedef bsl::allocator | allocator_type |
Public Member Functions | |
| JsonConverter () | |
| JsonConverter (const allocator_type &allocator) | |
| ~JsonConverter ()=default | |
| template<class TYPE > | |
| int | convert (bdljsn::Json *json, const TYPE &value, const ConvertToJsonOptions &options=ConvertToJsonOptions()) |
| template<class TYPE > | |
| int | convert (TYPE *value, const bdljsn::Json &json, const ConvertFromJsonOptions &options=ConvertFromJsonOptions()) |
| bsl::string | loggedMessages () const |
| allocator_type | get_allocator () const |
|
inline |
Create a JsonConverter object. Optionally specify an allocator (e.g., the address of a bslma::Allocator object) to supply memory; otherwise, the default allocator is used.
|
inlineexplicit |
|
default |
Destroy this object.
| int baljsn::JsonConverter::convert | ( | bdljsn::Json * | json, |
| const TYPE & | value, | ||
| const ConvertToJsonOptions & | options = ConvertToJsonOptions() |
||
| ) |
Load into the specified json the specified value of (template parameter) TYPE using the specified options. Return 0 on success, and a non-zero value otherwise. An error is returned if TYPE is not a top-level Sequence, Choice, or Array. The prior value of json is reset.
| int baljsn::JsonConverter::convert | ( | TYPE * | value, |
| const bdljsn::Json & | json, | ||
| const ConvertFromJsonOptions & | options = ConvertFromJsonOptions() |
||
| ) |
Load to the specified value of (template parameter) TYPE the value of the specified json using the specified options. Return 0 on success and a non-zero value otherwise. An error is returned if TYPE is not a top-level Sequence, Choice, or Array. The prior value of value is reset.
|
inline |
Return the allocator used by this object to supply memory.
|
inline |
Return a string containing any error, warning, or trace messages that were logged during the last call to the convert method. The log is reset each time convert is called.