cereal
A C++11 library for serialization
Classes | Macros | Functions
json.hpp File Reference

JSON input and output archives. More...

#include "cereal/cereal.hpp"
#include "cereal/details/util.hpp"
#include "rapidjson/prettywriter.h"
#include "rapidjson/ostreamwrapper.h"
#include "rapidjson/istreamwrapper.h"
#include "rapidjson/document.h"
#include "cereal/external/base64.hpp"
#include <limits>
#include <sstream>
#include <stack>
#include <vector>
#include <string>

Go to the source code of this file.

Classes

struct  cereal::RapidJSONException
 An exception thrown when rapidjson fails an internal assertion. More...
 
class  cereal::JSONOutputArchive
 An output archive designed to save data to JSON. More...
 
class  cereal::JSONOutputArchive::Options
 A class containing various advanced options for the JSON archive. More...
 
class  cereal::JSONInputArchive
 An input archive designed to load data from JSON. More...
 

Macros

#define RAPIDJSON_ASSERT_THROWS
 
#define RAPIDJSON_ASSERT(x)
 
#define RAPIDJSON_WRITE_DEFAULT_FLAGS   kWriteNanAndInfFlag
 
#define RAPIDJSON_PARSE_DEFAULT_FLAGS   kParseFullPrecisionFlag | kParseNanAndInfFlag
 

Functions

template<class T >
void cereal::prologue (JSONOutputArchive &, NameValuePair< T > const &)
 Prologue for NVPs for JSON archives. More...
 
template<class T >
void cereal::prologue (JSONInputArchive &, NameValuePair< T > const &)
 Prologue for NVPs for JSON archives.
 
template<class T >
void cereal::epilogue (JSONOutputArchive &, NameValuePair< T > const &)
 Epilogue for NVPs for JSON archives. More...
 
template<class T >
void cereal::epilogue (JSONInputArchive &, NameValuePair< T > const &)
 Epilogue for NVPs for JSON archives. More...
 
template<class T >
void cereal::prologue (JSONOutputArchive &, DeferredData< T > const &)
 Prologue for deferred data for JSON archives. More...
 
template<class T >
void cereal::prologue (JSONInputArchive &, DeferredData< T > const &)
 Prologue for deferred data for JSON archives.
 
template<class T >
void cereal::epilogue (JSONOutputArchive &, DeferredData< T > const &)
 Epilogue for deferred for JSON archives. More...
 
template<class T >
void cereal::epilogue (JSONInputArchive &, DeferredData< T > const &)
 Epilogue for deferred for JSON archives. More...
 
template<class T >
void cereal::prologue (JSONOutputArchive &ar, SizeTag< T > const &)
 Prologue for SizeTags for JSON archives. More...
 
template<class T >
void cereal::prologue (JSONInputArchive &, SizeTag< T > const &)
 Prologue for SizeTags for JSON archives.
 
template<class T >
void cereal::epilogue (JSONOutputArchive &, SizeTag< T > const &)
 Epilogue for SizeTags for JSON archives. More...
 
template<class T >
void cereal::epilogue (JSONInputArchive &, SizeTag< T > const &)
 Epilogue for SizeTags for JSON archives.
 
template<class T , traits::EnableIf<!std::is_arithmetic< T >::value, !traits::has_minimal_base_class_serialization< T, traits::has_minimal_output_serialization, JSONOutputArchive >::value, !traits::has_minimal_output_serialization< T, JSONOutputArchive >::value > = traits::sfinae>
void cereal::prologue (JSONOutputArchive &ar, T const &)
 Prologue for all other types for JSON archives (except minimal types) More...
 
template<class T , traits::EnableIf<!std::is_arithmetic< T >::value, !traits::has_minimal_base_class_serialization< T, traits::has_minimal_input_serialization, JSONInputArchive >::value, !traits::has_minimal_input_serialization< T, JSONInputArchive >::value > = traits::sfinae>
void cereal::prologue (JSONInputArchive &ar, T const &)
 Prologue for all other types for JSON archives. More...
 
template<class T , traits::EnableIf<!std::is_arithmetic< T >::value, !traits::has_minimal_base_class_serialization< T, traits::has_minimal_output_serialization, JSONOutputArchive >::value, !traits::has_minimal_output_serialization< T, JSONOutputArchive >::value > = traits::sfinae>
void cereal::epilogue (JSONOutputArchive &ar, T const &)
 Epilogue for all other types other for JSON archives (except minimal types) More...
 
template<class T , traits::EnableIf<!std::is_arithmetic< T >::value, !traits::has_minimal_base_class_serialization< T, traits::has_minimal_input_serialization, JSONInputArchive >::value, !traits::has_minimal_input_serialization< T, JSONInputArchive >::value > = traits::sfinae>
void cereal::epilogue (JSONInputArchive &ar, T const &)
 Epilogue for all other types other for JSON archives. More...
 
void cereal::prologue (JSONOutputArchive &ar, std::nullptr_t const &)
 Prologue for arithmetic types for JSON archives.
 
void cereal::prologue (JSONInputArchive &, std::nullptr_t const &)
 Prologue for arithmetic types for JSON archives.
 
void cereal::epilogue (JSONOutputArchive &, std::nullptr_t const &)
 Epilogue for arithmetic types for JSON archives.
 
void cereal::epilogue (JSONInputArchive &, std::nullptr_t const &)
 Epilogue for arithmetic types for JSON archives.
 
template<class CharT , class Traits , class Alloc >
void cereal::prologue (JSONOutputArchive &ar, std::basic_string< CharT, Traits, Alloc > const &)
 Prologue for strings for JSON archives.
 
template<class CharT , class Traits , class Alloc >
void cereal::prologue (JSONInputArchive &, std::basic_string< CharT, Traits, Alloc > const &)
 Prologue for strings for JSON archives.
 
template<class CharT , class Traits , class Alloc >
void cereal::epilogue (JSONOutputArchive &, std::basic_string< CharT, Traits, Alloc > const &)
 Epilogue for strings for JSON archives.
 
template<class CharT , class Traits , class Alloc >
void cereal::epilogue (JSONInputArchive &, std::basic_string< CharT, Traits, Alloc > const &)
 Epilogue for strings for JSON archives.
 
template<class T >
void cereal::CEREAL_SAVE_FUNCTION_NAME (JSONOutputArchive &ar, NameValuePair< T > const &t)
 Serializing NVP types to JSON.
 
template<class T >
void cereal::CEREAL_LOAD_FUNCTION_NAME (JSONInputArchive &ar, NameValuePair< T > &t)
 
void cereal::CEREAL_SAVE_FUNCTION_NAME (JSONOutputArchive &ar, std::nullptr_t const &t)
 Saving for nullptr to JSON.
 
void cereal::CEREAL_LOAD_FUNCTION_NAME (JSONInputArchive &ar, std::nullptr_t &t)
 Loading arithmetic from JSON.
 
template<class T , traits::EnableIf< std::is_arithmetic< T >::value > = traits::sfinae>
void cereal::CEREAL_SAVE_FUNCTION_NAME (JSONOutputArchive &ar, T const &t)
 Saving for arithmetic to JSON.
 
template<class T , traits::EnableIf< std::is_arithmetic< T >::value > = traits::sfinae>
void cereal::CEREAL_LOAD_FUNCTION_NAME (JSONInputArchive &ar, T &t)
 Loading arithmetic from JSON.
 
template<class CharT , class Traits , class Alloc >
void cereal::CEREAL_SAVE_FUNCTION_NAME (JSONOutputArchive &ar, std::basic_string< CharT, Traits, Alloc > const &str)
 saving string to JSON
 
template<class CharT , class Traits , class Alloc >
void cereal::CEREAL_LOAD_FUNCTION_NAME (JSONInputArchive &ar, std::basic_string< CharT, Traits, Alloc > &str)
 loading string from JSON
 
template<class T >
void cereal::CEREAL_SAVE_FUNCTION_NAME (JSONOutputArchive &, SizeTag< T > const &)
 Saving SizeTags to JSON.
 
template<class T >
void cereal::CEREAL_LOAD_FUNCTION_NAME (JSONInputArchive &ar, SizeTag< T > &st)
 Loading SizeTags from JSON.
 

Detailed Description

JSON input and output archives.

Macro Definition Documentation

◆ RAPIDJSON_ASSERT

#define RAPIDJSON_ASSERT (   x)
Value:
if(!(x)){ \
throw ::cereal::RapidJSONException("rapidjson internal assertion failure: " #x); }

Function Documentation

◆ epilogue() [1/7]

template<class T >
void cereal::epilogue ( JSONInputArchive ,
DeferredData< T > const &   
)
inline

Epilogue for deferred for JSON archives.

Do nothing for the defer wrapper

◆ epilogue() [2/7]

template<class T >
void cereal::epilogue ( JSONInputArchive ,
NameValuePair< T > const &   
)
inline

Epilogue for NVPs for JSON archives.

NVPs do not start or finish nodes - they just set up the names

◆ epilogue() [3/7]

template<class T , traits::EnableIf<!std::is_arithmetic< T >::value, !traits::has_minimal_base_class_serialization< T, traits::has_minimal_input_serialization, JSONInputArchive >::value, !traits::has_minimal_input_serialization< T, JSONInputArchive >::value > = traits::sfinae>
void cereal::epilogue ( JSONInputArchive ar,
T const &   
)
inline

Epilogue for all other types other for JSON archives.

Epilogue for arithmetic types for JSON archives.

◆ epilogue() [4/7]

template<class T >
void cereal::epilogue ( JSONOutputArchive ,
DeferredData< T > const &   
)
inline

Epilogue for deferred for JSON archives.

NVPs do not start or finish nodes - they just set up the names

◆ epilogue() [5/7]

template<class T >
void cereal::epilogue ( JSONOutputArchive ,
NameValuePair< T > const &   
)
inline

Epilogue for NVPs for JSON archives.

NVPs do not start or finish nodes - they just set up the names

◆ epilogue() [6/7]

template<class T >
void cereal::epilogue ( JSONOutputArchive ,
SizeTag< T > const &   
)
inline

Epilogue for SizeTags for JSON archives.

SizeTags are strictly ignored for JSON

◆ epilogue() [7/7]

template<class T , traits::EnableIf<!std::is_arithmetic< T >::value, !traits::has_minimal_base_class_serialization< T, traits::has_minimal_output_serialization, JSONOutputArchive >::value, !traits::has_minimal_output_serialization< T, JSONOutputArchive >::value > = traits::sfinae>
void cereal::epilogue ( JSONOutputArchive ar,
T const &   
)
inline

Epilogue for all other types other for JSON archives (except minimal types)

Epilogue for arithmetic types for JSON archives.

Finishes the node created in the prologue

Minimal types do not start or finish nodes

◆ prologue() [1/5]

template<class T , traits::EnableIf<!std::is_arithmetic< T >::value, !traits::has_minimal_base_class_serialization< T, traits::has_minimal_input_serialization, JSONInputArchive >::value, !traits::has_minimal_input_serialization< T, JSONInputArchive >::value > = traits::sfinae>
void cereal::prologue ( JSONInputArchive ar,
T const &   
)
inline

Prologue for all other types for JSON archives.

Prologue for arithmetic types for JSON archives.

◆ prologue() [2/5]

template<class T >
void cereal::prologue ( JSONOutputArchive ,
DeferredData< T > const &   
)
inline

Prologue for deferred data for JSON archives.

Do nothing for the defer wrapper

◆ prologue() [3/5]

template<class T >
void cereal::prologue ( JSONOutputArchive ,
NameValuePair< T > const &   
)
inline

Prologue for NVPs for JSON archives.

NVPs do not start or finish nodes - they just set up the names

◆ prologue() [4/5]

template<class T >
void cereal::prologue ( JSONOutputArchive ar,
SizeTag< T > const &   
)
inline

Prologue for SizeTags for JSON archives.

SizeTags are strictly ignored for JSON, they just indicate that the current node should be made into an array

◆ prologue() [5/5]

template<class T , traits::EnableIf<!std::is_arithmetic< T >::value, !traits::has_minimal_base_class_serialization< T, traits::has_minimal_output_serialization, JSONOutputArchive >::value, !traits::has_minimal_output_serialization< T, JSONOutputArchive >::value > = traits::sfinae>
void cereal::prologue ( JSONOutputArchive ar,
T const &   
)
inline

Prologue for all other types for JSON archives (except minimal types)

Prologue for arithmetic types for JSON archives.

Starts a new node, named either automatically or by some NVP, that may be given data by the type about to be archived

Minimal types do not start or finish nodes