BDE 4.39.x Production Release
Loading...
Searching...
No Matches
baljsn::JsonConverter Class Reference

#include <baljsn_jsonconverter.h>

Detailed Description

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.

See baljsn_jsonconverter

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
 

Member Typedef Documentation

◆ allocator_type

Constructor & Destructor Documentation

◆ JsonConverter() [1/2]

baljsn::JsonConverter::JsonConverter ( )
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.

◆ JsonConverter() [2/2]

baljsn::JsonConverter::JsonConverter ( const allocator_type allocator)
inlineexplicit

◆ ~JsonConverter()

baljsn::JsonConverter::~JsonConverter ( )
default

Destroy this object.

Member Function Documentation

◆ convert() [1/2]

template<class TYPE >
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.

◆ convert() [2/2]

template<class TYPE >
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.

◆ get_allocator()

JsonConverter::allocator_type baljsn::JsonConverter::get_allocator ( ) const
inline

Return the allocator used by this object to supply memory.

Note
Note that if no allocator was supplied at construction the default allocator in effect at construction is used.

◆ loggedMessages()

bsl::string baljsn::JsonConverter::loggedMessages ( ) const
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.


The documentation for this class was generated from the following file: