mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-11-29 22:36:19 +08:00
21 lines
859 B
Markdown
21 lines
859 B
Markdown
# Anonymous fields
|
|
|
|
If you do not want to serialize field names, you do not have to use `rfl::Field`. You can just write your struct like this:
|
|
|
|
```cpp
|
|
struct Person {
|
|
std::string first_name;
|
|
std::string last_name;
|
|
std::vector<Person> children;
|
|
};
|
|
```
|
|
|
|
This is referred to as anonymous fields. It is particularly relevant if you are using a binary format.
|
|
|
|
This can be fully serialized and deserialized using `rfl::json::read` and `rfl::json::write`. No further annotations are needed.
|
|
|
|
However, there are a two things you have to keep in mind:
|
|
|
|
1) If you annotate *some* of the fields using either `rfl::Field` or `rfl::Flatten`, then you must annotate *all* of them using one of these two.
|
|
2) If you are combining structs using `rfl::Flatten`, then all fields in all structs must be annotated using either using either `rfl::Field` or `rfl::Flatten`.
|