Stateful wrapper object of an input stream for JSON deserialization.
More...
#include <donut/json.hpp>
Stateful wrapper object of an input stream for JSON deserialization.
◆ Reader()
Construct a reader with an input stream as input.
- Parameters
-
◆ readNull()
Read a single JSON value of type Null from the input.
- Returns
- the location of the parsed value.
- Exceptions
-
json::Error | on invalid input. |
std::bad_alloc | on allocation failure. |
any | exception thrown by the underlying input stream. |
- See also
- Parser::parseNull()
-
readValue()
◆ readBoolean()
Read a single JSON value of type Boolean from the input.
- Parameters
-
value | reference to the output value to write the parsed result to. |
- Returns
- the location of the parsed value.
- Exceptions
-
json::Error | on invalid input. |
std::bad_alloc | on allocation failure. |
any | exception thrown by the underlying input stream. |
- Note
- If any exception is thrown, the output value is left unmodified.
- See also
- Parser::parseBoolean()
◆ readString() [1/2]
Read a single JSON value of type String from the input.
- Parameters
-
value | reference to the output value to write the parsed result to. |
- Returns
- the location of the parsed value.
- Exceptions
-
json::Error | on invalid input. |
std::bad_alloc | on allocation failure. |
any | exception thrown by the underlying input stream. |
- Note
- If any exception is thrown, the output value is left unmodified.
- See also
- Parser::parseString()
◆ readString() [2/2]
Read a single JSON value of type String from the input into any value that can be assigned from a standard string or deserialized from JSON.
- Parameters
-
value | reference to the output value to write the parsed result to. |
- Returns
- the location of the parsed value.
- Exceptions
-
json::Error | on invalid input. |
std::bad_alloc | on allocation failure. |
any | exception thrown by the underlying input iterator. |
any | exception thrown by the underlying assignment operator or Deserializer implementation of the given value type. |
◆ readNumber() [1/2]
Read a single JSON value of type Number from the input.
- Parameters
-
value | reference to the output value to write the parsed result to. |
- Returns
- the location of the parsed value.
- Exceptions
-
json::Error | on invalid input. |
std::bad_alloc | on allocation failure. |
any | exception thrown by the underlying input stream. |
- Note
- If any exception is thrown, the output value is left unmodified.
- See also
- Parser::parseNumber()
◆ readNumber() [2/2]
Read a single JSON value of type Number from the input into any value that Number can be explicitly converted to.
- Parameters
-
value | reference to the output value to write the parsed result to. |
- Returns
- the location of the parsed value.
- Exceptions
-
json::Error | on invalid input. |
std::bad_alloc | on allocation failure. |
any | exception thrown by the underlying input iterator. |
any | exception thrown by the underlying conversion or assignment operator of the given value type. |
◆ readObject() [1/2]
Read a single JSON value of type Object from the input.
- Parameters
-
value | reference to the output value to write the parsed result to. |
- Returns
- the location of the parsed value.
- Exceptions
-
json::Error | on invalid input. |
std::bad_alloc | on allocation failure. |
any | exception thrown by the underlying input stream. |
- Note
- If any exception is thrown, the output value is left unmodified.
- See also
- Parser::parseObject()
◆ readObject() [2/2]
Read a single JSON object from the input into any container of key-value pairs where the key and value types are default-constructible and deserializable from JSON, and where the container supports clear()
and emplace(std::move(key), std::move(value))
.
- Parameters
-
value | reference to the output container to write the parsed results into. |
- Returns
- the location of the beginning of the parsed object.
- Exceptions
-
json::Error | on invalid input. |
std::bad_alloc | on allocation failure. |
any | exception thrown by the underlying input iterator. |
any | exception thrown by the default constructors of the given key/value types. |
any | exception thrown by the Deserializer implementations of the given key/value types. |
any | exception thrown by clear() or emplace(std::move(key), std::move(value)) . |
- Warning
- If an exception is thrown, the output value may be left empty or with some successfully parsed properties added to it, since they are not removed automatically if a later operation fails.
◆ readArray() [1/2]
Read a single JSON value of type Array from the input.
- Parameters
-
value | reference to the output value to write the parsed result to. |
- Returns
- the location of the parsed value.
- Exceptions
-
json::Error | on invalid input. |
std::bad_alloc | on allocation failure. |
any | exception thrown by the underlying input stream. |
- Note
- If any exception is thrown, the output value is left unmodified.
- See also
- Parser::parseArray()
◆ readArray() [2/2]
Read a single JSON array from the input into any container of elements that are default-constructible and deserializable from JSON, where the container supports clear()
and push_back(std::move(element))
.
- Parameters
-
value | reference to the output container to write the parsed results into. |
- Returns
- the location of the beginning of the parsed array.
- Exceptions
-
json::Error | on invalid input. |
std::bad_alloc | on allocation failure. |
any | exception thrown by the underlying input iterator. |
any | exception thrown by the default constructor of the given element type. |
any | exception thrown by the Deserializer implementation of the given element type. |
any | exception thrown by clear() or push_back(std::move(element)) . |
- Warning
- If an exception is thrown, the output value may be left empty or with some successfully parsed items added to it, since they are not removed automatically if a later operation fails.
◆ readValue()
Read a single JSON value from the input.
- Parameters
-
value | reference to the output value to write the parsed result to. |
- Returns
- the location of the parsed value.
- Exceptions
-
json::Error | on invalid input. |
std::bad_alloc | on allocation failure. |
any | exception thrown by the underlying input stream. |
- Note
- If any exception is thrown, the output value is left unmodified.
- See also
- Parser::parseValue()
◆ readOptional()
Read a single nullable JSON value from the input into any value that is default-constructible, move-assignable and dereferencable, and where the dereferenced value type is default-constructible, deserializable from JSON and can be move-assigned into the value.
If a null value is read, the output is assigned a default-constructed value of its own type.
- Parameters
-
value | reference to the output value to write the result to. |
- Returns
- the location of the parsed value.
- Exceptions
-
json::Error | on invalid input. |
std::bad_alloc | on allocation failure. |
any | exception thrown by the underlying input iterator. |
any | exception thrown by the default constructor of the given value type or its dereferenced type. |
any | exception thrown by the Deserializer implementation of the given value's dereferenced type. |
any | exception thrown by the assignment operator of the given value type. |
◆ readAggregate()
Read a single JSON value from the input into any value of aggregate type whose fields are deserializable from JSON.
- Parameters
-
value | reference to the output value whose fields to write the parsed results into. |
- Returns
- the location of the beginning of the parsed value.
- Exceptions
-
json::Error | on invalid input. |
std::bad_alloc | on allocation failure. |
any | exception thrown by the underlying input iterator. |
any | exception thrown by the Deserializer implementations of the given field types. |
- Warning
- If an exception is thrown, the output value may be left with some successfully parsed fields, since they are not reset automatically if a later operation fails.
◆ deserialize()
template<typename T >
void donut::json::Reader::deserialize |
( |
T & |
value | ) |
|
|
inline |
Read a JSON value from the input into any value that is deserializable from JSON using its corresponding implementation of Deserializer.
- Parameters
-
value | reference to the output value to write the parsed result to. |
- Exceptions
-
any | exception thrown by the underlying input stream. |
any | exception thrown by the Deserializer implementation of T. |
◆ options
The current options of the deserialization process.
The documentation for this struct was generated from the following file: