cxxtools::JsonDeserializer Class Reference

This class converts json format to cxxtools::SerializationInfo. More...

#include <cxxtools/jsondeserializer.h>

Inheritance diagram for cxxtools::JsonDeserializer:

Public Member Functions

 JsonDeserializer (std::istream &in, TextCodec< Char, char > *codec=new Utf8Codec())
 JsonDeserializer (std::basic_istream< Char > &in)
 JsonDeserializer ()
void begin ()
int advance (Char ch)
void finish ()
- Public Member Functions inherited from cxxtools::Deserializer
 Deserializer ()
virtual ~Deserializer ()
template<typename T >
void deserialize (T &type) const
 Deserialize an object.
template<typename T >
void deserialize (T &type, const std::string &name) const
SerializationInfosi ()
const SerializationInfosi () const
void clear ()
SerializationInfocurrent ()
const SerializationInfocurrent () const
void setCategory (SerializationInfo::Category category)
void setName (const std::string &name)
void setTypeName (const std::string &type)
void setValue (const String &value)
void setValue (const std::string &value)
void setValue (const char *value)
void setValue (bool value)
void setValue (int_type value)
void setValue (unsigned_type value)
void setValue (long double value)
void setNull ()
void beginMember (const std::string &name, const std::string &type, SerializationInfo::Category category)
void leaveMember ()

Additional Inherited Members

- Public Types inherited from cxxtools::Deserializer
typedef long int_type
typedef unsigned long unsigned_type

Detailed Description

This class converts json format to cxxtools::SerializationInfo.

Here is a usage example:

#include <iostream>
struct Configuration
struct Indent
int length;
bool useSpace;
std::string encoding;
std::vector<std::string> plugIns;
Indent indent;
void operator>>= (const cxxtools::SerializationInfo& si, Configuration::Indent& indent)
si.getMember("length") >>= indent.length;
si.getMember("use_space") >>= indent.useSpace;
void operator>>= (const cxxtools::SerializationInfo& si, Configuration& config)
si.getMember("encoding") >>= config.encoding;
si.getMember("plug-ins") >>= config.plugIns;
si.getMember("indent") >>= config.indent;
int main(int argc, char* argv[])
// define a empty config object
Configuration config;
// read json configuration struct from stdin:
cxxtools::JsonDeserializer deserializer(std::cin);
// print configuration
std::cout << "encoding=" << config.encoding << '\n'
<< "plugIns=";
for (unsigned n = 0; n < config.plugIns.size(); ++n)
std::cout << config.plugIns[n] << ' ';
std::cout << '\n'
<< "indent.length=" << config.indent.length << '\n'
<< "indent.useSpace=" << config.indent.useSpace << '\n';
catch (const std::exception& e)
std::cerr << e.what() << std::endl;

Constructor & Destructor Documentation

cxxtools::JsonDeserializer::JsonDeserializer ( std::istream &  in,
TextCodec< Char, char > *  codec = new Utf8Codec() 
cxxtools::JsonDeserializer::JsonDeserializer ( std::basic_istream< Char > &  in)
cxxtools::JsonDeserializer::JsonDeserializer ( )

Member Function Documentation

int cxxtools::JsonDeserializer::advance ( Char  ch)
void cxxtools::JsonDeserializer::begin ( )

Reimplemented from cxxtools::Deserializer.

void cxxtools::JsonDeserializer::finish ( )

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