mirror of
https://github.com/nlohmann/json.git
synced 2026-10-08 18:05:19 +00:00
Merge branch 'json-view/15-view-bench' into json-view/16-view-simd
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -26,6 +26,7 @@ header. See also the [macro overview page](../../features/macros.md).
|
||||
- [**JSON_HAS_CPP_11**<br>**JSON_HAS_CPP_14**<br>**JSON_HAS_CPP_17**<br>**JSON_HAS_CPP_20**](json_has_cpp_11.md) - set supported C++ standard
|
||||
- [**JSON_HAS_FILESYSTEM**<br>**JSON_HAS_EXPERIMENTAL_FILESYSTEM**](json_has_filesystem.md) - control `std::filesystem` support
|
||||
- [**JSON_HAS_RANGES**](json_has_ranges.md) - control `std::ranges` support
|
||||
- [**JSON_HAS_STATIC_RTTI**](json_has_static_rtti.md) - control RTTI (run time type information) support
|
||||
- [**JSON_HAS_STD_FORMAT**](json_has_std_format.md) - control `std::format`/`std::formatter` support
|
||||
- [**JSON_HAS_THREE_WAY_COMPARISON**](json_has_three_way_comparison.md) - control 3-way comparison support
|
||||
- [**JSON_NO_AUTOMATIC_UDLS**](json_no_automatic_udls.md) - do not include the user-defined string literals (UDLs) automatically
|
||||
|
||||
@@ -31,7 +31,7 @@ Therefore, assertions can be switched off by defining `NDEBUG`.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Example 1: default behavior"
|
||||
??? example "Example: default behavior"
|
||||
|
||||
The following code will trigger an assertion at runtime:
|
||||
|
||||
@@ -53,7 +53,7 @@ Therefore, assertions can be switched off by defining `NDEBUG`.
|
||||
Assertion failed: (m_value.object->find(key) != m_value.object->end()), function operator[], file json.hpp, line 2144.
|
||||
```
|
||||
|
||||
??? example "Example 2: user-defined behavior"
|
||||
??? example "Example: user-defined behavior"
|
||||
|
||||
The assertion reporting can be changed by defining `JSON_ASSERT(x)` differently.
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ The default value is `0` (disabled — existing behavior is preserved).
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Default behavior (macro not defined)"
|
||||
??? example "Example: default behavior (macro not defined)"
|
||||
|
||||
Without the macro, single-element brace initialization wraps the value in an array:
|
||||
|
||||
@@ -88,7 +88,7 @@ The default value is `0` (disabled — existing behavior is preserved).
|
||||
}
|
||||
```
|
||||
|
||||
??? example "Opt-in copy semantics (macro defined to 1)"
|
||||
??? example "Example: opt-in copy semantics (macro defined to 1)"
|
||||
|
||||
With the macro, single-element brace initialization copies/moves the value:
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ When the macro is not defined, the library will define it to its default value.
|
||||
|
||||
The output shows the start/end positions of all the objects and fields in the JSON string.
|
||||
|
||||
??? example "Example 2: using only diagnostic positions in exceptions"
|
||||
??? example "Example: using only diagnostic positions in exceptions"
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/diagnostic_positions_exception.cpp"
|
||||
@@ -95,7 +95,7 @@ When the macro is not defined, the library will define it to its default value.
|
||||
|
||||
The output shows the exception with start/end positions only.
|
||||
|
||||
??? example "Example 3: using extended diagnostics with positions enabled in exceptions"
|
||||
??? example "Example: using extended diagnostics with positions enabled in exceptions"
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/diagnostics_extended_positions.cpp"
|
||||
|
||||
@@ -43,7 +43,7 @@ When the macro is not defined, the library will define it to its default value.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Example 1: default behavior"
|
||||
??? example "Example: default behavior"
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/diagnostics_standard.cpp"
|
||||
@@ -57,7 +57,7 @@ When the macro is not defined, the library will define it to its default value.
|
||||
|
||||
This exception can be hard to debug if storing the value `#!c "12"` and accessing it is further apart.
|
||||
|
||||
??? example "Example 2: extended diagnostic messages"
|
||||
??? example "Example: extended diagnostic messages"
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/diagnostics_extended.cpp"
|
||||
@@ -71,7 +71,7 @@ When the macro is not defined, the library will define it to its default value.
|
||||
|
||||
Now the exception message contains a JSON Pointer `/address/housenumber` that indicates which value has the wrong type.
|
||||
|
||||
??? example "Example 3: using only diagnostic positions in exceptions"
|
||||
??? example "Example: using only diagnostic positions in exceptions"
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/diagnostic_positions_exception.cpp"
|
||||
|
||||
@@ -30,7 +30,7 @@ The default value is `0`.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Example 1: Disabled behavior"
|
||||
??? example "Example: Disabled behavior"
|
||||
|
||||
The code below forces the library **not** to create default serialization/deserialization functions `from_json` and `to_json`, meaning the code below
|
||||
**does not** compile.
|
||||
@@ -57,7 +57,7 @@ The default value is `0`.
|
||||
}
|
||||
```
|
||||
|
||||
??? example "Example 2: Serialize enum macro"
|
||||
??? example "Example: Serialize enum macro"
|
||||
|
||||
The code below forces the library **not** to create default serialization/deserialization functions `from_json` and `to_json`, but uses
|
||||
[`NLOHMANN_JSON_SERIALIZE_ENUM`](nlohmann_json_serialize_enum.md) to parse and serialize the enum.
|
||||
@@ -90,7 +90,7 @@ The default value is `0`.
|
||||
}
|
||||
```
|
||||
|
||||
??? example "Example 3: User-defined serialization/deserialization functions"
|
||||
??? example "Example: User-defined serialization/deserialization functions"
|
||||
|
||||
The code below forces the library **not** to create default serialization/deserialization functions `from_json` and `to_json`, but uses user-defined
|
||||
functions to parse and serialize the enum.
|
||||
|
||||
@@ -67,7 +67,7 @@ The default value is `0` (disabled — existing behavior is preserved).
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Default behavior (macro not defined)"
|
||||
??? example "Example: default behavior (macro not defined)"
|
||||
|
||||
```cpp
|
||||
#include <nlohmann/json.hpp>
|
||||
@@ -83,7 +83,7 @@ The default value is `0` (disabled — existing behavior is preserved).
|
||||
}
|
||||
```
|
||||
|
||||
??? example "Conversion disabled (macro defined to 1)"
|
||||
??? example "Example: conversion disabled (macro defined to 1)"
|
||||
|
||||
```cpp
|
||||
#define JSON_DISABLE_TUPLE_REFERENCE_CONVERSION 1
|
||||
|
||||
@@ -40,6 +40,13 @@ The default value is detected based on preprocessor macros such as `#!cpp __cplu
|
||||
...
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [JSON_HAS_FILESYSTEM / JSON_HAS_EXPERIMENTAL_FILESYSTEM](json_has_filesystem.md) - control `std::filesystem` support
|
||||
- [JSON_HAS_RANGES](json_has_ranges.md) - control `std::ranges` support
|
||||
- [JSON_HAS_THREE_WAY_COMPARISON](json_has_three_way_comparison.md) - control 3-way comparison support
|
||||
- [JSON_HAS_STD_FORMAT](json_has_std_format.md) - control `std::format`/`std::formatter` support
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.10.5.
|
||||
|
||||
@@ -52,6 +52,11 @@ The default value is detected based on the preprocessor macros `#!cpp __cpp_lib_
|
||||
...
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [JSON_HAS_CPP_11 / JSON_HAS_CPP_14 / JSON_HAS_CPP_17 / JSON_HAS_CPP_20 / JSON_HAS_CPP_23 /
|
||||
JSON_HAS_CPP_26](json_has_cpp_11.md) - set supported C++ standard
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.10.5.
|
||||
|
||||
@@ -40,6 +40,13 @@ When the macro is not defined, the library will define it to its default value.
|
||||
...
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [JSON_HAS_CPP_11 / JSON_HAS_CPP_14 / JSON_HAS_CPP_17 / JSON_HAS_CPP_20 / JSON_HAS_CPP_23 /
|
||||
JSON_HAS_CPP_26](json_has_cpp_11.md) - set supported C++ standard
|
||||
- [JSON_HAS_STD_FORMAT](json_has_std_format.md) - a similar feature-detection macro, for `std::format`/`std::formatter`
|
||||
support
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.11.0.
|
||||
|
||||
@@ -25,7 +25,12 @@ When the macro is not defined, the library will define it to its default value.
|
||||
|
||||
...
|
||||
```
|
||||
|
||||
|
||||
## See also
|
||||
|
||||
- [**operator ValueType**](../basic_json/operator_ValueType.md) - get a value (implicit); on C++17, this macro
|
||||
controls whether `std::any` is excluded from its candidate types
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.11.3.
|
||||
|
||||
@@ -36,6 +36,10 @@ When the macro is not defined, the library will define it to its default value.
|
||||
...
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [`std::formatter<basic_json>`](../basic_json/std_formatter.md) - format JSON values with `std::format`
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.13.0.
|
||||
|
||||
@@ -27,6 +27,11 @@ When the macro is not defined, the library will define it to its default value.
|
||||
...
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [**operator<=>**](../basic_json/operator_spaceship.md) - 3-way compare JSON values
|
||||
- [**operator==**](../json_pointer/operator_eq.md) - compare JSON pointers for equality
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.11.0.
|
||||
|
||||
@@ -30,6 +30,11 @@ By default, `#!cpp JSON_NO_IO` is not defined.
|
||||
...
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [**operator<<**](../operator_ltlt.md) - serialize to stream
|
||||
- [**operator>>**](../operator_gtgt.md) - deserialize from stream
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.10.0.
|
||||
|
||||
@@ -43,6 +43,10 @@ Copying and comparing fall back to working without the call stack there, as they
|
||||
...
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [FAQ: Thread safety](../../home/faq.md#thread-safety)
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.12.1.
|
||||
- Added in version 3.13.0.
|
||||
|
||||
@@ -79,7 +79,7 @@ The default value is `0` (disabled — existing behavior is preserved).
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Default behavior (macro not defined)"
|
||||
??? example "Example: default behavior (macro not defined)"
|
||||
|
||||
Without the macro, the character after a number is consumed:
|
||||
|
||||
@@ -99,7 +99,7 @@ The default value is `0` (disabled — existing behavior is preserved).
|
||||
}
|
||||
```
|
||||
|
||||
??? example "Opt-in precise stream position (macro defined to 1)"
|
||||
??? example "Example: opt-in precise stream position (macro defined to 1)"
|
||||
|
||||
With the macro, the stream is positioned right after the number:
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ By default, the macro is not defined.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
??? example "Example: switch off the version check"
|
||||
|
||||
The code below switches off the warning about including a different version of the library.
|
||||
|
||||
@@ -35,7 +35,7 @@ By default, the macro is not defined.
|
||||
...
|
||||
```
|
||||
|
||||
!!! example
|
||||
??? example "Example: warning about a different library version"
|
||||
|
||||
The following warning will be shown in case a different version of the library was already included:
|
||||
|
||||
@@ -43,6 +43,11 @@ By default, the macro is not defined.
|
||||
Already included a different version of the library!
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [NLOHMANN_JSON_VERSION_MAJOR, NLOHMANN_JSON_VERSION_MINOR,
|
||||
NLOHMANN_JSON_VERSION_PATCH](nlohmann_json_version_major.md) - library version information
|
||||
|
||||
## Version history
|
||||
|
||||
Added in version 3.11.0.
|
||||
- Added in version 3.11.0.
|
||||
|
||||
@@ -28,6 +28,11 @@ By default, the macro is not defined.
|
||||
...
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [JSON_HAS_CPP_11 / JSON_HAS_CPP_14 / JSON_HAS_CPP_17 / JSON_HAS_CPP_20 / JSON_HAS_CPP_23 /
|
||||
JSON_HAS_CPP_26](json_has_cpp_11.md) - set supported C++ standard
|
||||
|
||||
## Version history
|
||||
|
||||
Added in version 3.2.0.
|
||||
- Added in version 3.2.0.
|
||||
|
||||
@@ -85,7 +85,7 @@ The default value is `0` (disabled — existing behavior is preserved).
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Default behavior (macro not defined)"
|
||||
??? example "Example: default behavior (macro not defined)"
|
||||
|
||||
Without the macro, a NUL byte silently ends parsing at that point:
|
||||
|
||||
@@ -101,7 +101,7 @@ The default value is `0` (disabled — existing behavior is preserved).
|
||||
}
|
||||
```
|
||||
|
||||
??? example "Opt-in strict handling (macro defined to 1)"
|
||||
??? example "Example: opt-in strict handling (macro defined to 1)"
|
||||
|
||||
With the macro, a NUL byte is rejected like any other unexpected byte:
|
||||
|
||||
@@ -124,6 +124,7 @@ The default value is `0` (disabled — existing behavior is preserved).
|
||||
|
||||
## See also
|
||||
|
||||
- [:simple-cmake: JSON_StrictNulHandling](../../integration/cmake.md#json_strictnulhandling) - CMake option to control the macro
|
||||
- [FAQ: NUL bytes in the input](../../home/faq.md#nul-bytes-in-the-input)
|
||||
- [**parse**](../basic_json/parse.md) - deserialize from a compatible input
|
||||
- [**accept**](../basic_json/accept.md) - check if the input is valid JSON
|
||||
|
||||
@@ -26,6 +26,8 @@ When the macro is not defined, the library behaves as if it were defined to its
|
||||
To prepare existing code, define `JSON_USE_GLOBAL_UDLS` to `0` and bring the string literals into scope where
|
||||
needed. Refer to any of the [string literals](#see-also) for details.
|
||||
|
||||
See the [migration guide](../../integration/migration_guide.md#import-namespace-literals-for-udls) for how to update existing code.
|
||||
|
||||
!!! hint "CMake option"
|
||||
|
||||
The placement of user-defined string literals can also be controlled with the CMake option
|
||||
@@ -39,7 +41,7 @@ When the macro is not defined, the library behaves as if it were defined to its
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Example 1: Default behavior"
|
||||
??? example "Example: Default behavior"
|
||||
|
||||
The code below shows the default behavior using the `_json` UDL.
|
||||
|
||||
@@ -62,7 +64,7 @@ When the macro is not defined, the library behaves as if it were defined to its
|
||||
42
|
||||
```
|
||||
|
||||
??? example "Example 2: Namespaced UDLs"
|
||||
??? example "Example: Namespaced UDLs"
|
||||
|
||||
The code below shows how UDLs need to be brought into scope before using `_json` when `JSON_USE_GLOBAL_UDLS` is
|
||||
defined to `0`.
|
||||
|
||||
@@ -24,6 +24,8 @@ By default, implicit conversions are enabled.
|
||||
You can prepare existing code by already defining `JSON_USE_IMPLICIT_CONVERSIONS` to `0` and replace any implicit
|
||||
conversions with calls to [`get`](../basic_json/get.md).
|
||||
|
||||
See the [migration guide](../../integration/migration_guide.md#replace-implicit-conversions) for how to update existing code.
|
||||
|
||||
!!! tip "Automatic migration"
|
||||
|
||||
The community-maintained clang-tidy check `modernize-nlohmann-json-explicit-conversions` rewrites implicit
|
||||
|
||||
@@ -53,6 +53,8 @@ When the macro is not defined, the library will define it to its default value.
|
||||
|
||||
New code should not depend on it and existing code should try to remove or rewrite expressions relying on it.
|
||||
|
||||
See the [migration guide](../../integration/migration_guide.md#miscellaneous-functions) for how to update existing code.
|
||||
|
||||
!!! hint "CMake option"
|
||||
|
||||
Legacy comparison can also be controlled with the CMake option
|
||||
|
||||
@@ -62,9 +62,15 @@ By default, `#!cpp JSON_USE_SIMDUTF` is not defined and the portable C++11 scala
|
||||
|
||||
!!! hint "Testing this configuration"
|
||||
|
||||
The unit tests can be built against the simdutf backend with the CMake option `JSON_TestSimdutf` (`OFF` by
|
||||
default), which fetches simdutf and defines `JSON_USE_SIMDUTF` for every test target. The `ci_test_simdutf` target
|
||||
runs the whole test suite in that configuration.
|
||||
The unit tests can be built against the simdutf backend with the CMake option
|
||||
[`JSON_TestSimdutf`](../../integration/cmake.md#json_testsimdutf) (`OFF` by default), which fetches simdutf and
|
||||
defines `JSON_USE_SIMDUTF` for every test target. The `ci_test_simdutf` target runs the whole test suite in that
|
||||
configuration.
|
||||
|
||||
## See also
|
||||
|
||||
- [:simple-cmake: JSON_TestSimdutf](../../integration/cmake.md#json_testsimdutf) - CMake option to build the unit
|
||||
tests against the simdutf backend
|
||||
|
||||
## Version history
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ void to_json(BasicJsonType& j, const B& b) {
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE"
|
||||
??? example "Example: (1) NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE"
|
||||
|
||||
Consider the following complete example:
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ See the examples below for the concrete generated code.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Example (1): NLOHMANN_DEFINE_TYPE_INTRUSIVE"
|
||||
??? example "Example: (1) NLOHMANN_DEFINE_TYPE_INTRUSIVE"
|
||||
|
||||
Consider the following complete example:
|
||||
|
||||
@@ -112,7 +112,7 @@ See the examples below for the concrete generated code.
|
||||
--8<-- "examples/nlohmann_define_type_intrusive_explicit.cpp"
|
||||
```
|
||||
|
||||
??? example "Example (2): NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT"
|
||||
??? example "Example: (2) NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT"
|
||||
|
||||
Consider the following complete example:
|
||||
|
||||
@@ -142,7 +142,7 @@ See the examples below for the concrete generated code.
|
||||
|
||||
Note how a default-initialized `person` object is used in the `from_json` to fill missing values.
|
||||
|
||||
??? example "Example (3): NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE"
|
||||
??? example "Example: (3) NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE"
|
||||
Consider the following complete example:
|
||||
|
||||
```cpp hl_lines="22"
|
||||
|
||||
@@ -82,7 +82,7 @@ See the examples below for the concrete generated code.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Example (1): NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE"
|
||||
??? example "Example: (1) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE"
|
||||
|
||||
Consider the following complete example:
|
||||
|
||||
@@ -110,7 +110,7 @@ See the examples below for the concrete generated code.
|
||||
--8<-- "examples/nlohmann_define_type_non_intrusive_explicit.cpp"
|
||||
```
|
||||
|
||||
??? example "Example (2): NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT"
|
||||
??? example "Example: (2) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT"
|
||||
|
||||
Consider the following complete example:
|
||||
|
||||
@@ -141,7 +141,7 @@ See the examples below for the concrete generated code.
|
||||
|
||||
Note how a default-initialized `person` object is used in the `from_json` to fill missing values.
|
||||
|
||||
??? example "Example (3): NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE"
|
||||
??? example "Example: (3) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE"
|
||||
|
||||
Consider the following complete example:
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ For further information please refer to the corresponding macros without `WITH_N
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Example (1): NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_NAMES"
|
||||
??? example "Example: NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_NAMES"
|
||||
|
||||
Consider the following complete example:
|
||||
|
||||
@@ -73,6 +73,21 @@ For further information please refer to the corresponding macros without `WITH_N
|
||||
--8<-- "examples/nlohmann_define_type_non_intrusive_with_names_explicit.cpp"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [NLOHMANN_DEFINE_TYPE_INTRUSIVE, NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT,
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE](nlohmann_define_type_intrusive.md) - the macros these variants add
|
||||
custom JSON key names to
|
||||
- [NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE, NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT,
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE](nlohmann_define_type_non_intrusive.md) - the macros these
|
||||
variants add custom JSON key names to
|
||||
- [NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE, NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT,
|
||||
NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE, NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE,
|
||||
NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT,
|
||||
NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE](nlohmann_define_derived_type.md) - similar macros for
|
||||
derived types, also available with custom names
|
||||
- [Arbitrary Type Conversions](../../features/arbitrary_types.md) - overview of type conversion mechanisms
|
||||
|
||||
## Version history
|
||||
|
||||
1. Added in version 3.13.0.
|
||||
- Added in version 3.13.0.
|
||||
|
||||
@@ -44,7 +44,7 @@ inline void from_json(const BasicJsonType& j, type& e);
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Example 1: Basic usage"
|
||||
??? example "Example: Basic usage"
|
||||
|
||||
The example shows how `NLOHMANN_JSON_SERIALIZE_ENUM` can be used to serialize/deserialize both classical enums and
|
||||
C++11 enum classes:
|
||||
@@ -59,7 +59,7 @@ inline void from_json(const BasicJsonType& j, type& e);
|
||||
--8<-- "examples/nlohmann_json_serialize_enum.output"
|
||||
```
|
||||
|
||||
??? example "Example 2: Multiple conversions for one enumerator"
|
||||
??? example "Example: Multiple conversions for one enumerator"
|
||||
|
||||
The example shows how to use multiple conversions for a single enumerator. In the example, `Color::red` will always
|
||||
be *serialized* to `"red"`, because the first occurring conversion. The second conversion, however, offers an
|
||||
|
||||
@@ -47,7 +47,7 @@ inline void from_json(const BasicJsonType& j, type& e);
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Example 1: Basic usage"
|
||||
??? example "Example: Basic usage"
|
||||
|
||||
The example shows how `NLOHMANN_JSON_SERIALIZE_ENUM_STRICT` can be used to serialize/deserialize both classical enums and
|
||||
C++11 enum classes:
|
||||
@@ -62,7 +62,7 @@ inline void from_json(const BasicJsonType& j, type& e);
|
||||
--8<-- "examples/nlohmann_json_serialize_enum_strict.output"
|
||||
```
|
||||
|
||||
??? example "Example 2: Multiple conversions for one enumerator"
|
||||
??? example "Example: Multiple conversions for one enumerator"
|
||||
|
||||
The example shows how to use multiple conversions for a single enumerator. In the example, `Color::red` will always
|
||||
be *serialized* to `"red"`, because the first occurring conversion. The second conversion, however, offers an
|
||||
@@ -78,7 +78,7 @@ inline void from_json(const BasicJsonType& j, type& e);
|
||||
--8<-- "examples/nlohmann_json_serialize_enum_strict_2.output"
|
||||
```
|
||||
|
||||
??? example "Example 3: exceptions on invalid serialization"
|
||||
??? example "Example: exceptions on invalid serialization"
|
||||
|
||||
The example shows how an invalid serialization causes an exception to be thrown. In the example,
|
||||
Color::unknown is not defined in the mapping used to call `NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`
|
||||
|
||||
Reference in New Issue
Block a user