Reflection for RapidJSON
0.0.17
Reflection for serializing/deserializing with RapidJSON
Toggle main menu visibility
Loading...
Searching...
No Matches
json
reflector-chronoutilities.h
Go to the documentation of this file.
1
#ifndef REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_CHRONO_UTILITIES_H
2
#define REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_CHRONO_UTILITIES_H
3
10
11
#include "
./reflector.h
"
12
13
#include <c++utilities/chrono/datetime.h>
14
#include <c++utilities/chrono/timespan.h>
15
#include <c++utilities/conversion/conversionexception.h>
16
17
namespace
ReflectiveRapidJSON
{
18
namespace
JsonReflector
{
19
20
// define functions to "push" values to a RapidJSON array or object
21
22
template
<>
23
inline
void
push<CppUtilities::DateTime>
(
24
const
CppUtilities::DateTime &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
25
{
26
const
std::string str(reflectable.toIsoString());
27
value.SetString(str.data(),
rapidJsonSize
(str.size()), allocator);
28
}
29
30
template
<>
31
inline
void
push<CppUtilities::TimeSpan>
(
32
const
CppUtilities::TimeSpan &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
33
{
34
const
std::string str(reflectable.toString());
35
value.SetString(str.data(),
rapidJsonSize
(str.size()), allocator);
36
}
37
38
// define functions to "pull" values from a RapidJSON array or object
39
40
template
<>
41
inline
void
pull<CppUtilities::DateTime>
(CppUtilities::DateTime &reflectable,
42
const
RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value,
JsonDeserializationErrors
*errors)
43
{
44
std::string str;
45
pull
(str, value, errors);
46
try
{
47
reflectable = CppUtilities::DateTime::fromIsoStringGmt(str.data());
48
}
catch
(
const
CppUtilities::ConversionException &) {
49
if
(errors) {
50
errors->
reportConversionError
(
JsonType::String
);
51
}
52
}
53
}
54
55
template
<>
56
inline
void
pull<CppUtilities::TimeSpan>
(CppUtilities::TimeSpan &reflectable,
57
const
RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value,
JsonDeserializationErrors
*errors)
58
{
59
std::string str;
60
pull
(str, value, errors);
61
try
{
62
reflectable = CppUtilities::TimeSpan::fromString(str.data());
63
}
catch
(
const
CppUtilities::ConversionException &) {
64
if
(errors) {
65
errors->
reportConversionError
(
JsonType::String
);
66
}
67
}
68
}
69
70
}
// namespace JsonReflector
71
}
// namespace ReflectiveRapidJSON
72
73
#endif
// REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_CHRONO_UTILITIES_H
reflector.h
Contains functions to (de)serialize basic types such as int, double, bool, std::string,...
ReflectiveRapidJSON::JsonReflector
The JsonReflector namespace contains helper functions to ease the use of RapidJSON for automatic (de)...
Definition
reflector.h:48
ReflectiveRapidJSON::JsonReflector::pull
void pull(Type &reflectable, const RAPIDJSON_NAMESPACE::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char > >::ConstObject &value, JsonDeserializationErrors *errors)
Pulls the reflectable which has a custom type from the specified object.
Definition
reflector-boosthana.h:40
ReflectiveRapidJSON::JsonReflector::push< CppUtilities::TimeSpan >
void push< CppUtilities::TimeSpan >(const CppUtilities::TimeSpan &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
Definition
reflector-chronoutilities.h:31
ReflectiveRapidJSON::JsonReflector::push< CppUtilities::DateTime >
void push< CppUtilities::DateTime >(const CppUtilities::DateTime &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
Definition
reflector-chronoutilities.h:23
ReflectiveRapidJSON::JsonReflector::pull< CppUtilities::DateTime >
void pull< CppUtilities::DateTime >(CppUtilities::DateTime &reflectable, const RAPIDJSON_NAMESPACE::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char > > &value, JsonDeserializationErrors *errors)
Definition
reflector-chronoutilities.h:41
ReflectiveRapidJSON::JsonReflector::rapidJsonSize
constexpr RAPIDJSON_NAMESPACE::SizeType rapidJsonSize(std::size_t size)
Casts the specified size to the size type used by RapidJSON ensuring no overflow happens.
Definition
reflector.h:53
ReflectiveRapidJSON::JsonReflector::pull< CppUtilities::TimeSpan >
void pull< CppUtilities::TimeSpan >(CppUtilities::TimeSpan &reflectable, const RAPIDJSON_NAMESPACE::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char > > &value, JsonDeserializationErrors *errors)
Definition
reflector-chronoutilities.h:56
ReflectiveRapidJSON
Definition
traits.h:13
ReflectiveRapidJSON::JsonType::String
@ String
Definition
errorhandling.h:41
ReflectiveRapidJSON::JsonDeserializationErrors
The JsonDeserializationErrors struct can be passed to fromJson() for error handling.
Definition
errorhandling.h:154
ReflectiveRapidJSON::JsonDeserializationErrors::reportConversionError
void reportConversionError(JsonType jsonType)
Reports a conversion error.
Definition
errorhandling.h:250
Generated on
for Reflection for RapidJSON by
1.18.0