Reflection for RapidJSON 0.0.16
Reflection for serializing/deserializing with RapidJSON
Loading...
Searching...
No Matches
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
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
17namespace ReflectiveRapidJSON {
18namespace JsonReflector {
19
20// define functions to "push" values to a RapidJSON array or object
21
22template <>
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
30template <>
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
40template <>
41inline 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) {
51 }
52 }
53}
54
55template <>
56inline 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) {
66 }
67 }
68}
69
70} // namespace JsonReflector
71} // namespace ReflectiveRapidJSON
72
73#endif // REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_CHRONO_UTILITIES_H
Contains functions to (de)serialize basic types such as int, double, bool, std::string,...
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.
void push< CppUtilities::TimeSpan >(const CppUtilities::TimeSpan &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
void push< CppUtilities::DateTime >(const CppUtilities::DateTime &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
void pull< CppUtilities::DateTime >(CppUtilities::DateTime &reflectable, const RAPIDJSON_NAMESPACE::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char > > &value, JsonDeserializationErrors *errors)
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
void pull< CppUtilities::TimeSpan >(CppUtilities::TimeSpan &reflectable, const RAPIDJSON_NAMESPACE::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char > > &value, JsonDeserializationErrors *errors)
The JsonDeserializationErrors struct can be passed to fromJson() for error handling.
void reportConversionError(JsonType jsonType)
Reports a conversion error.