1 #ifndef REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_CHRONO_UTILITIES_H 2 #define REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_CHRONO_UTILITIES_H 13 #include <c++utilities/chrono/datetime.h> 14 #include <c++utilities/chrono/timespan.h> 15 #include <c++utilities/conversion/conversionexception.h> 18 namespace JsonReflector {
23 inline void push<ChronoUtilities::DateTime>(
24 const ChronoUtilities::DateTime &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
26 const std::string str(reflectable.toIsoString());
27 value.SetString(str.data(),
rapidJsonSize(str.size()), allocator);
31 inline void push<ChronoUtilities::TimeSpan>(
32 const ChronoUtilities::TimeSpan &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
34 const std::string str(reflectable.toString());
35 value.SetString(str.data(),
rapidJsonSize(str.size()), allocator);
41 inline void pull<ChronoUtilities::DateTime>(ChronoUtilities::DateTime &reflectable,
45 pull(str, value, errors);
47 reflectable = ChronoUtilities::DateTime::fromIsoStringGmt(str.data());
48 }
catch (
const ConversionUtilities::ConversionException &) {
56 inline void pull<ChronoUtilities::TimeSpan>(ChronoUtilities::TimeSpan &reflectable,
60 pull(str, value, errors);
62 reflectable = ChronoUtilities::TimeSpan::fromString(str.data());
63 }
catch (
const ConversionUtilities::ConversionException &) {
73 #endif // REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_CHRONO_UTILITIES_H
constexpr RAPIDJSON_NAMESPACE::SizeType rapidJsonSize(std::size_t size)
Casts the specified size to the size type used by RapidJSON ensuring no overflow happens.
The JsonDeserializationErrors struct can be passed to fromJson() for error handling.
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.
Contains functions to (de)serialize basic types such as int, double, bool, std::string, std::vector, ...