JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
jsonv::deserialize_options Class Referencefinal

Configuration for various deserialization options. This becomes part of the deserialization_context. More...

#include <jsonv/serialization/deserialize.hpp>

Public Types

enum class  on_error { fail_immediately , collect_all }
 When an error is encountered during deserialization, what should happen? More...
 
enum class  duplicate_key_action { replace , ignore , exception }
 When an object key has the same value as a previously-seen key, what should happen? More...
 
using size_type = deserialization_error::problem_list::size_type
 

Public Member Functions

 deserialize_options () noexcept
 Create an instance with the default options.
 
on_error failure_mode () const noexcept
 See on_error. The default failure mode is fail_immediately.
 
deserialize_options & failure_mode (on_error mode)
 See on_error. The default failure mode is fail_immediately.
 
size_type max_failures () const
 The number of problems to collect before giving up.
 
deserialize_options & max_failures (size_type limit)
 The number of problems to collect before giving up.
 
duplicate_key_action on_duplicate_key () const
 See duplicate_key_action. The default action is replace.
 
deserialize_options & on_duplicate_key (duplicate_key_action action)
 See duplicate_key_action. The default action is replace.
 

Static Public Member Functions

static deserialize_options create_default ()
 Create a default set of options.
 

Detailed Description

Configuration for various deserialization options. This becomes part of the deserialization_context.

Definition at line 248 of file deserialize.hpp.

Member Typedef Documentation

◆ size_type

using jsonv::deserialize_options::size_type = deserialization_error::problem_list::size_type

Definition at line 251 of file deserialize.hpp.

Member Enumeration Documentation

◆ duplicate_key_action

When an object key has the same value as a previously-seen key, what should happen?

Enumerator
replace 

Replace the previous value with the new one.

The final value of the key in the object will be the last-encountered one.

For example: { "a": 1, "a": 2, "a": 3 } will end with { "a": 3 }.

ignore 

Ignore the new values.

The final value of the key in the object will be the first-encountered one.

    For example: `{ "a": 1, "a": 2, "a": 3 }` will end with `{ "a": 1 }`. 
exception 

Repeated keys should raise a deserialization_error.

Definition at line 275 of file deserialize.hpp.

◆ on_error

When an error is encountered during deserialization, what should happen?

Enumerator
fail_immediately 

Report the first problem and stop, so the deserialization_error thrown describes one thing that went wrong.

collect_all 

Keep deserializing past a problem wherever something knows how to resume, so the deserialization_error thrown at the end describes as many of them as it can.

Resuming is only possible where a composite knows where its next element begins – the next element of an array, the next key of an object – which is why deserialization_context::recover is asked rather than told. A failure with no enclosing composite to resume into still ends deserialization with a single problem.

Collecting gathers diagnostics; it does not produce partially-deserialized objects. A deserialization which recovered from anything still throws, so this changes how much the error explains and never whether one happens.

See also
deserialize_options::max_failures

Definition at line 254 of file deserialize.hpp.

Member Function Documentation

◆ failure_mode()

on_error jsonv::deserialize_options::failure_mode ( ) const
inlinenoexcept

See on_error. The default failure mode is fail_immediately.

Definition at line 304 of file deserialize.hpp.

◆ max_failures() [1/2]

size_type jsonv::deserialize_options::max_failures ( ) const
inline

The number of problems to collect before giving up.

This is only applicable if the failure_mode is on_error::collect_all. By default, this value is 10.

This is a threshold deserialization stops at rather than a cap on the list it reports. A single failure which reports several problems at once – an adapter recording a batch of them before returning, or throwing a deserialization_error carrying several – is taken whole rather than torn in half, so the final list can exceed the limit by that batch. Truncating would drop diagnostics to enforce a bound whose purpose is to stop the walk, not to edit the report.

A limit of 0 or 1 makes the first problem the last, which is on_error::fail_immediately in all but name.

You should probably not set this value to an unreasonably high number, as each error encountered must be stored in memory for some period of time.

Definition at line 325 of file deserialize.hpp.

◆ max_failures() [2/2]

deserialize_options & jsonv::deserialize_options::max_failures ( size_type  limit)

The number of problems to collect before giving up.

This is only applicable if the failure_mode is on_error::collect_all. By default, this value is 10.

This is a threshold deserialization stops at rather than a cap on the list it reports. A single failure which reports several problems at once – an adapter recording a batch of them before returning, or throwing a deserialization_error carrying several – is taken whole rather than torn in half, so the final list can exceed the limit by that batch. Truncating would drop diagnostics to enforce a bound whose purpose is to stop the walk, not to edit the report.

A limit of 0 or 1 makes the first problem the last, which is on_error::fail_immediately in all but name.

You should probably not set this value to an unreasonably high number, as each error encountered must be stored in memory for some period of time.

◆ on_duplicate_key()

duplicate_key_action jsonv::deserialize_options::on_duplicate_key ( ) const
inline

See duplicate_key_action. The default action is replace.

Definition at line 333 of file deserialize.hpp.


The documentation for this class was generated from the following file: