mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-04 01:06:19 +08:00
Adapted the documentation to the possibility of leaving out rfl::Field
This commit is contained in:
+32
-1
@@ -9,7 +9,38 @@ all fields will be flattened to a single JSON object.
|
||||
|
||||
If there are duplicate field names, you will get a compile-time error.
|
||||
|
||||
## Example: Every employee is a person.
|
||||
## Example: Every employee is a person
|
||||
|
||||
```cpp
|
||||
struct Person {
|
||||
std::string first_name;
|
||||
std::string last_name;
|
||||
int age;
|
||||
};
|
||||
|
||||
struct Employee {
|
||||
rfl::Flatten<Person> person;
|
||||
std::string employer;
|
||||
float salary;
|
||||
};
|
||||
|
||||
const auto employee = Employee{
|
||||
.person = Person{.first_name = "Homer",
|
||||
.last_name = "Simpson",
|
||||
.age = 45},
|
||||
.employer = "Mr. Burns",
|
||||
.salary = 60000.0};
|
||||
|
||||
const auto json_str = rfl::json::write(employee);
|
||||
```
|
||||
|
||||
This flattens all fields into a single JSON object:
|
||||
|
||||
```json
|
||||
{"first_name":"Homer","last_name":"Simpson","age":45,"salary":60000.0}
|
||||
```
|
||||
|
||||
## Example, using the `rfl::Field`-syntax.
|
||||
|
||||
```cpp
|
||||
struct Person {
|
||||
|
||||
Reference in New Issue
Block a user