Skip to content

Commit

Permalink
Add dumping for types with to_json free function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapptz committed Mar 10, 2015
1 parent 9bdfe56 commit 368afad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ There's an API in place to dump (i.e. serialise) C++ objects into JSON construct
as an object. The key (i.e. ``p.first``) will be dumped in accordance to :func:`json::key` while the value will be
recursively called with :func:`json::dump`.
- If the type is :class:`value` then it will print with the above in mind with its internal value.
- If the type has ``to_json`` then it will call it and then dump the resulting value recursively.

.. function:: void key(OStream& out, const T& t, const format_options& options)

Expand Down
5 changes: 5 additions & 0 deletions jsonpp/dump.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ inline OStream& dump(OStream& out, const T& t, format_options opt = {}) {
return out;
}

template<typename OStream, typename T, EnableIf<has_to_json<T>, Not<Or<is_object<T>, is_string<T>, is_array<T>>>> = 0>
inline OStream& dump(OStream& out, const T& t, format_options opt = {}) {
return dump(out, to_json(t), opt);
}

template<typename T>
inline std::string dump_string(const T& value, format_options opt = {}) {
std::ostringstream ss;
Expand Down

0 comments on commit 368afad

Please sign in to comment.