https://github.com/beached/daw_json_link_describe
Library that allows JSON Link to serialize types mapped by boost.describe
https://github.com/beached/daw_json_link_describe
Last synced: 15 days ago
JSON representation
Library that allows JSON Link to serialize types mapped by boost.describe
- Host: GitHub
- URL: https://github.com/beached/daw_json_link_describe
- Owner: beached
- License: other
- Created: 2022-05-04T06:54:00.000Z (about 3 years ago)
- Default Branch: release
- Last Pushed: 2022-05-24T02:33:00.000Z (almost 3 years ago)
- Last Synced: 2023-04-02T12:28:30.232Z (about 2 years ago)
- Language: C++
- Size: 38.1 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
Example of how to use Boost.Describe descriptions as a way to map aggregates
See tests/src folder for a working example
Requires C++17 and uses [DAW JSON Link](https://github.com/beached/daw_json_link) v3 and [Boost.Describe](https://www.boost.org/doc/libs/1_79_0/libs/describe/doc/html/describe.html)
To describe a struct, only public members are supported, see the Boost.Describe documentation. It will be similar to
```cpp
struct X {
int m1;
int m2;
};
BOOST_DESCRIBE_STRUCT( X, ( ), ( m1, m2 ) )int main( ) {
std::string_view json_doc = R"json(
{
"m1": 55,
"m2": 123
}
)json";auto val = daw::json::from_json( json_doc );
assert( val.m1 == 55 );
assert( val.m2 == 123 );
puts( daw::json::to_json( val ).c_str( ) );
}
```The specialization of `daw::json::use_boost_describe` is necessary. After this from_json and to_json will work with the
mapped type