mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-02 16:16:19 +08:00
Merge branch 'main' of github.com:getml/reflect-cpp
This commit is contained in:
@@ -101,7 +101,9 @@ reflect-cpp supports the following containers from the C++ standard library:
|
||||
- `std::array`
|
||||
- `std::deque`
|
||||
- `std::forward_list`
|
||||
- `std::map`
|
||||
- `std::map`
|
||||
- `std::multimap`
|
||||
- `std::multiset`
|
||||
- `std::list`
|
||||
- `std::optional`
|
||||
- `std::pair`
|
||||
@@ -110,7 +112,9 @@ reflect-cpp supports the following containers from the C++ standard library:
|
||||
- `std::string`
|
||||
- `std::tuple`
|
||||
- `std::unique_ptr`
|
||||
- `std::unordered_map`
|
||||
- `std::unordered_map`
|
||||
- `std::unordered_multimap`
|
||||
- `std::unordered_multiset`
|
||||
- `std::unordered_set`
|
||||
- `std::variant`
|
||||
- `std::vector`
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
1.7) [rfl::Timestamp](https://github.com/getml/reflect-cpp/blob/main/docs/timestamps.md) - For serializing and deserializing timestamps.
|
||||
|
||||
1.8) [Standard containers](https://github.com/getml/reflect-cpp/blob/main/docs/standard_containers.md) - Describes how reflect-cpp treats containers in the standard library.
|
||||
|
||||
## 2) Custom classes
|
||||
|
||||
2.1) [Custom classes](https://github.com/getml/reflect-cpp/blob/main/docs/custom_classes.md) - For custom classes with private fields.
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
# Support for standard containers
|
||||
|
||||
The serialization and deserialization of containers is handled as follows:
|
||||
|
||||
`std::map<std::string, ...>` and `std::unordered_map<std::string, ...>` are treated
|
||||
as objects.
|
||||
|
||||
Consider the following map:
|
||||
|
||||
```cpp
|
||||
std::map<std::string, std::string> homer;
|
||||
homer["firstName"] = "Homer";
|
||||
homer["lastName"] = "Simpson";
|
||||
```
|
||||
|
||||
This will be represented as follows:
|
||||
|
||||
```json
|
||||
{"firstName":"Homer","lastName":"Simpson"}
|
||||
```
|
||||
|
||||
All other supported standard containers
|
||||
(other than `std::variant`, `std::optional`, `std::unique_ptr` and `std::shared_ptr`)
|
||||
will be represented as arrays. Containers for which the `value_type`
|
||||
is a key-value-pair, will be represented as arrays of pairs.
|
||||
|
||||
Consider the following map:
|
||||
|
||||
```cpp
|
||||
std::map<int, Person> children;
|
||||
children[1] = Person{.first_name = "Bart", .last_name = "Simpson"};
|
||||
children[2] = Person{.first_name = "Lisa", .last_name = "Simpson"};
|
||||
children[3] = Person{.first_name = "Maggie", .last_name = "Simpson"};
|
||||
```
|
||||
|
||||
This will be represented as follows:
|
||||
|
||||
```json
|
||||
[[1,{"firstName":"Bart","lastName":"Simpson"}],[2,{"firstName":"Lisa","lastName":"Simpson"}],[3,{"firstName":"Maggie","lastName":"Simpson"}]]
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user