$darkmode
#include <iostream>#include <string>#include <vector>#include <fmt/format.h>#include <CLI/CLI.hpp>#include <boost/optional.hpp>#include <fable/confable.hpp>#include <fable/schema.hpp>#include <fable/schema/boost_optional.hpp>#include <fable/utility.hpp>Classes | |
| struct | Address |
| struct | Contact |
Enumerations | |
| enum class | PhoneType { Home , Mobile , Work , Other } |
Functions | |
| int | main (int argc, char **argv) |
In this example application, we will define structs to serialize and deserialize JSON for contact persons.
We will be using the JSON from this Wikipedia article as our source format:
https://en.wikipedia.org/w/index.php?title=JSON&oldid=1027546414
The application should be able to serialize and deserialize to something like this:
{
"firstName": "John",
"lastName": "Smith",
"isAlive": true,
"age": 27,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "office",
"number": "646 555-4567"
}
],
"children": [],
"spouse": null
}
While we don't actually need to specify separate structs for the address, it improves readability significantly and makes working with optionals possible.