19#include <jsonv/version.hpp>
49 std::optional<jsonv::version> ver = std::nullopt,
50 const void* userdata =
nullptr
64 void serialize(const T& from,
writer& to)
const
66 serialize(
typeid(T),
static_cast<const void*
>(&from), to);
94 return to_json(
typeid(T),
static_cast<const void*
>(&from));
117template <
typename T,
typename FSerialize>
120 if constexpr (std::invocable<const FSerialize&, const serialization_context&, const T&, writer&>)
124 else if constexpr (std::invocable<const FSerialize&, const T&, writer&>)
128 else if constexpr (std::invocable<const FSerialize&, const serialization_context&, const T&>)
130 to.
write(func(context, from));
134 static_assert(std::invocable<const FSerialize&, const T&>,
135 "A serialization function must be callable as (const serialization_context&, const T&, writer&), "
136 "(const T&, writer&), (const serialization_context&, const T&) or (const T&)"
139 to.
write(func(from));
156JSONV_PUBLIC void serialize_document(
const serialization_context& context,
157 const std::type_info& type,
164 const std::type_info& type,
208 return detail::serialize_to_string(
serialization_context(fmts),
typeid(T),
static_cast<const void*
>(&from));
224 return detail::serialize_to_string(
context,
typeid(T),
static_cast<const void*
>(&from));
238 detail::serialize_document(
serialization_context(fmts),
typeid(T),
static_cast<const void*
>(&from), to);
250 detail::serialize_document(
context,
typeid(T),
static_cast<const void*
>(&from), to);
Provides extra information to routines used for deserialization and serialization.
Provides extra information to routines used for serialization: the formats to find other serializers ...
value to_json(const std::type_info &type, const void *from) const
Dynamically convert a type into a JSON value.
serialization_context()
Create a new instance using the default formats (formats::global).
serialization_context(jsonv::formats fmt, std::optional< jsonv::version > ver=std::nullopt, const void *userdata=nullptr)
Create a new instance using the given fmt, ver and userdata.
void serialize(const std::type_info &type, const void *from, writer &to) const
Write the object of the given type at from into to using the formats associated with this context.
value to_json(const T &from) const
Convenience function for converting a C++ object into a JSON value.
Represents a single JSON value, which can be any one of a potential kind, each behaving slightly diff...
A writer instance writes a JSON ast_node sequence to some form of sink: an encoder,...
writer & write(const value &source)
Write the whole of source as one value, as encoder::encode does.
Copyright (c) 2014-2020 by Travis Gockel.
Copyright (c) 2015-2020 by Travis Gockel.
Copyright (c) 2012-2020 by Travis Gockel.
#define JSONV_NODISCARD
Warn if the caller discards the result of this function.
#define JSONV_PUBLIC
This function or class is part of the public API for JSON Voorhees.
std::string serialize(const T &from, const formats &fmts=formats::global())
Serialize from into JSON text using fmts (by default jsonv::formats::global()).
value to_json(const T &from, const formats &fmts)
Encode a JSON value from from using the provided fmts.
The exception a failed serialization throws.
Copyright (c) 2012-2020 by Travis Gockel.