Wt  3.3.9
Public Member Functions | List of all members
Wt::Dbo::JsonSerializer Class Reference

An action to serialize objects to JSON. More...

#include <Wt/Dbo/Json>

Public Member Functions

 JsonSerializer (std::ostream &out)
 Creates a JsonSerializer that writes to an std::ostream. More...
 
virtual ~JsonSerializer ()
 Destructor.
 
template<typename T >
void serialize (const T &t)
 Serialize the given object. More...
 
template<typename T >
void serialize (const ptr< T > &t)
 Serialize the object that is pointed to by the given ptr. More...
 
template<typename T >
void serialize (const std::vector< ptr< T > > &v)
 Serialize an std::vector of ptrs. More...
 
template<typename T >
void serialize (const collection< ptr< T > > &c)
 Serialize a collection of ptrs. More...
 

Detailed Description

An action to serialize objects to JSON.

This class is an Action that serializes objects to an ostream. These objects must implement the persist() method. It also has support for serializing ptrs to these objects, std::vectors of ptrs, and collections of ptrs.

It will follow one-to-one and ManyToOne relations in one way: weak_ptr and collection fields are followed and serialized, for ptr fields only the id is output.

No extraneous whitespace is output.

Constructor & Destructor Documentation

Wt::Dbo::JsonSerializer::JsonSerializer ( std::ostream &  out)

Creates a JsonSerializer that writes to an std::ostream.

Note that the std::ostream is not flushed to automatically. The flush will happen automatically when this JsonSerializer is destructed.

Member Function Documentation

template<typename T >
void Wt::Dbo::JsonSerializer::serialize ( const T &  t)

Serialize the given object.

Serializes a plain object that implements the persist() method.

template<typename T >
void Wt::Dbo::JsonSerializer::serialize ( const ptr< T > &  t)

Serialize the object that is pointed to by the given ptr.

This method does the same as the plain object serializer, but also adds an extra id field.

template<typename T >
void Wt::Dbo::JsonSerializer::serialize ( const std::vector< ptr< T > > &  v)

Serialize an std::vector of ptrs.

Serializes each ptr in the vector individually, and puts it in an Array.

template<typename T >
void Wt::Dbo::JsonSerializer::serialize ( const collection< ptr< T > > &  c)

Serialize a collection of ptrs.

Serializes each ptr in the collection individually, and puts it in an Array.

The typical usage scenario of this method is to serialize the results of a query to JSON.


Generated on Tue Nov 21 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.11