mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-11-29 22:36:19 +08:00
22 lines
821 B
Markdown
22 lines
821 B
Markdown
# Error messages
|
|
|
|
reflect-cpp returns clear and comprehensive error messages:
|
|
|
|
```cpp
|
|
const std::string faulty_json_string =
|
|
R"({"firstName":"Homer","lastName":12345,"town":"Springfield","birthday":"04/19/1987","age":145,"email":"homer(at)simpson.com"})";
|
|
const auto result = rfl::json::read<Person>(faulty_json_string);
|
|
```
|
|
|
|
Yields the following error message:
|
|
|
|
```
|
|
Found 5 errors:
|
|
1) Failed to parse field 'lastName': Could not cast to string.
|
|
2) Failed to parse field 'birthday': String '04/19/1987' did not match format '%Y-%m-%d'.
|
|
3) Failed to parse field 'age': Value expected to be less than or equal to 130, but got 145.
|
|
4) Failed to parse field 'email': String 'homer(at)simpson.com' did not match format 'Email': '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'.
|
|
5) Field named 'children' not found.
|
|
```
|
|
|