mirror of
https://github.com/nlohmann/json.git
synced 2026-10-03 05:00:30 +00:00
deploy: 95e9a5931c
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -65,6 +65,12 @@ The default value is `0` (disabled — existing behavior is preserved).
|
||||
for CBOR or MessagePack, are never affected by this trimming; their full extent - including a genuine trailing
|
||||
`0x00` - is always preserved, in both states of this macro.
|
||||
|
||||
!!! note "ABI compatibility"
|
||||
|
||||
The value of this macro is encoded in the [namespace](../../features/namespace.md) (tag `_snul`), resulting in
|
||||
distinct symbol names. Translation units compiled with and without it can therefore be linked into the same program
|
||||
without One Definition Rule (ODR) violations, but they cannot exchange instances of library types.
|
||||
|
||||
!!! tip "Workaround without the macro"
|
||||
|
||||
To reject a NUL byte without enabling this macro, trim your input yourself before calling `parse()`:
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -41,6 +41,10 @@ This macro must be defined **before** including `<nlohmann/json.hpp>`. Defining
|
||||
|
||||
Enabling it also changes how a `char` array (including a string literal, e.g. `json::parse("123")`) is read: such an array normally carries a trailing `'\0'` contributed by the compiler, not by the source text. With this macro enabled, that one trailing byte is trimmed if present so that parsing a string literal keeps working; every other byte in the array - including any `'\0'` that is not the very last element - is read as real data and rejected like any other unexpected byte. Arrays of any other element type (`unsigned char`, `std::uint8_t`, ...), as used for CBOR or MessagePack, are never affected by this trimming; their full extent - including a genuine trailing `0x00` - is always preserved, in both states of this macro.
|
||||
|
||||
ABI compatibility
|
||||
|
||||
The value of this macro is encoded in the [namespace](https://json.nlohmann.me/features/namespace/index.md) (tag `_snul`), resulting in distinct symbol names. Translation units compiled with and without it can therefore be linked into the same program without One Definition Rule (ODR) violations, but they cannot exchange instances of library types.
|
||||
|
||||
Workaround without the macro
|
||||
|
||||
To reject a NUL byte without enabling this macro, trim your input yourself before calling `parse()`:
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -57,7 +57,8 @@ Summary:
|
||||
: name of the base type (class, struct) `type` is derived from
|
||||
|
||||
`member` (in)
|
||||
: name of the member variable to serialize/deserialize; up to 63 members can be given as a comma-separated list
|
||||
: name of the member variable to serialize/deserialize; up to 63 members can be given as a comma-separated
|
||||
list, which may also be empty
|
||||
|
||||
## Default definition
|
||||
|
||||
@@ -127,6 +128,20 @@ void to_json(BasicJsonType& j, const B& b) {
|
||||
- Macros 4, 5, and 6 have the same prerequisites of [NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE](nlohmann_define_type_non_intrusive.md).
|
||||
- Serialization/deserialization of base types must be defined.
|
||||
|
||||
!!! info "Derived types without own members"
|
||||
|
||||
The member list may be empty. The macro then generates a `to_json`/`from_json` pair that only delegates to
|
||||
the base type, so `type` serializes exactly like `base_type`:
|
||||
|
||||
```cpp
|
||||
struct derived : base
|
||||
{
|
||||
NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE(derived, base)
|
||||
};
|
||||
```
|
||||
|
||||
The `WITH_NAMES` variants do not support this.
|
||||
|
||||
!!! warning "Implementation limits"
|
||||
|
||||
See Implementation limits for [NLOHMANN_DEFINE_TYPE_INTRUSIVE](nlohmann_define_type_intrusive.md) and
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -43,7 +43,7 @@ Summary:
|
||||
|
||||
`base_type` (in) : name of the base type (class, struct) `type` is derived from
|
||||
|
||||
`member` (in) : name of the member variable to serialize/deserialize; up to 63 members can be given as a comma-separated list
|
||||
`member` (in) : name of the member variable to serialize/deserialize; up to 63 members can be given as a comma-separated list, which may also be empty
|
||||
|
||||
## Default definition
|
||||
|
||||
@@ -112,6 +112,19 @@ Prerequisites
|
||||
- Macros 4, 5, and 6 have the same prerequisites of [NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE](https://json.nlohmann.me/api/macros/nlohmann_define_type_non_intrusive/index.md).
|
||||
- Serialization/deserialization of base types must be defined.
|
||||
|
||||
Derived types without own members
|
||||
|
||||
The member list may be empty. The macro then generates a `to_json`/`from_json` pair that only delegates to the base type, so `type` serializes exactly like `base_type`:
|
||||
|
||||
```
|
||||
struct derived : base
|
||||
{
|
||||
NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE(derived, base)
|
||||
};
|
||||
```
|
||||
|
||||
The `WITH_NAMES` variants do not support this.
|
||||
|
||||
Implementation limits
|
||||
|
||||
See Implementation limits for [NLOHMANN_DEFINE_TYPE_INTRUSIVE](https://json.nlohmann.me/api/macros/nlohmann_define_type_intrusive/index.md) and [NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE](https://json.nlohmann.me/api/macros/nlohmann_define_type_non_intrusive/index.md), respectively.
|
||||
|
||||
@@ -33,7 +33,8 @@ Summary:
|
||||
: name of the type (class, struct) to serialize/deserialize
|
||||
|
||||
`member` (in)
|
||||
: name of the member variable to serialize/deserialize; up to 63 members can be given as a comma-separated list
|
||||
: name of the member variable to serialize/deserialize; up to 63 members can be given as a comma-separated
|
||||
list, which may also be empty
|
||||
|
||||
## Default definition
|
||||
|
||||
@@ -58,6 +59,20 @@ See the examples below for the concrete generated code.
|
||||
|
||||
[GetNonDefNonCopy]: ../../features/arbitrary_types.md#how-can-i-use-get-for-non-default-constructiblenon-copyable-types
|
||||
|
||||
!!! info "Types without members"
|
||||
|
||||
The member list may be empty. The macro then generates a `to_json` that produces an empty JSON object
|
||||
`#!json {}`, and a `from_json` that reads no members:
|
||||
|
||||
```cpp
|
||||
struct marker
|
||||
{
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(marker)
|
||||
};
|
||||
```
|
||||
|
||||
The `WITH_NAMES` variants do not support this.
|
||||
|
||||
!!! warning "Implementation limits"
|
||||
|
||||
- The current implementation is limited to at most 63 member variables. If you want to serialize/deserialize types
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -24,7 +24,7 @@ Summary:
|
||||
|
||||
`type` (in) : name of the type (class, struct) to serialize/deserialize
|
||||
|
||||
`member` (in) : name of the member variable to serialize/deserialize; up to 63 members can be given as a comma-separated list
|
||||
`member` (in) : name of the member variable to serialize/deserialize; up to 63 members can be given as a comma-separated list, which may also be empty
|
||||
|
||||
## Default definition
|
||||
|
||||
@@ -46,6 +46,19 @@ Prerequisites
|
||||
1. The type `type` must be default constructible (except (3)). See [How can I use `get()` for non-default constructible/non-copyable types?](https://json.nlohmann.me/features/arbitrary_types/#how-can-i-use-get-for-non-default-constructiblenon-copyable-types) for how to overcome this limitation.
|
||||
1. The macro must be used inside the type (class/struct).
|
||||
|
||||
Types without members
|
||||
|
||||
The member list may be empty. The macro then generates a `to_json` that produces an empty JSON object `{}`, and a `from_json` that reads no members:
|
||||
|
||||
```
|
||||
struct marker
|
||||
{
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(marker)
|
||||
};
|
||||
```
|
||||
|
||||
The `WITH_NAMES` variants do not support this.
|
||||
|
||||
Implementation limits
|
||||
|
||||
- The current implementation is limited to at most 63 member variables. If you want to serialize/deserialize types with more than 63 member variables, you need to define the `to_json`/`from_json` functions manually.
|
||||
|
||||
@@ -33,7 +33,8 @@ Summary:
|
||||
: name of the type (class, struct) to serialize/deserialize
|
||||
|
||||
`member` (in)
|
||||
: name of the (public) member variable to serialize/deserialize; up to 63 members can be given as a comma-separated list
|
||||
: name of the (public) member variable to serialize/deserialize; up to 63 members can be given as a
|
||||
comma-separated list, which may also be empty
|
||||
|
||||
## Default definition
|
||||
|
||||
@@ -59,6 +60,18 @@ See the examples below for the concrete generated code.
|
||||
|
||||
[GetNonDefNonCopy]: ../../features/arbitrary_types.md#how-can-i-use-get-for-non-default-constructiblenon-copyable-types
|
||||
|
||||
!!! info "Types without members"
|
||||
|
||||
The member list may be empty. The macro then generates a `to_json` that produces an empty JSON object
|
||||
`#!json {}`, and a `from_json` that reads no members:
|
||||
|
||||
```cpp
|
||||
struct marker {};
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(marker)
|
||||
```
|
||||
|
||||
The `WITH_NAMES` variants do not support this.
|
||||
|
||||
!!! warning "Implementation limits"
|
||||
|
||||
- The current implementation is limited to at most 63 member variables. If you want to serialize/deserialize types
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -24,7 +24,7 @@ Summary:
|
||||
|
||||
`type` (in) : name of the type (class, struct) to serialize/deserialize
|
||||
|
||||
`member` (in) : name of the (public) member variable to serialize/deserialize; up to 63 members can be given as a comma-separated list
|
||||
`member` (in) : name of the (public) member variable to serialize/deserialize; up to 63 members can be given as a comma-separated list, which may also be empty
|
||||
|
||||
## Default definition
|
||||
|
||||
@@ -47,6 +47,17 @@ Prerequisites
|
||||
1. The macro must be used outside the type (class/struct).
|
||||
1. The passed members must be public.
|
||||
|
||||
Types without members
|
||||
|
||||
The member list may be empty. The macro then generates a `to_json` that produces an empty JSON object `{}`, and a `from_json` that reads no members:
|
||||
|
||||
```
|
||||
struct marker {};
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(marker)
|
||||
```
|
||||
|
||||
The `WITH_NAMES` variants do not support this.
|
||||
|
||||
Implementation limits
|
||||
|
||||
- The current implementation is limited to at most 63 member variables. If you want to serialize/deserialize types with more than 63 member variables, you need to define the `to_json`/`from_json` functions manually.
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user