{"id":19211367,"url":"https://github.com/truebrain/libdto-cpp","last_synced_at":"2025-07-27T12:05:18.936Z","repository":{"id":147275628,"uuid":"476003007","full_name":"TrueBrain/libdto-cpp","owner":"TrueBrain","description":"A very small example how a (header-only) DTO library in C++ could look","archived":false,"fork":false,"pushed_at":"2022-03-30T18:33:06.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-23T07:43:46.774Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TrueBrain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-30T18:24:59.000Z","updated_at":"2022-03-30T18:33:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"b72bcccb-f194-40c3-bf8e-f00516725193","html_url":"https://github.com/TrueBrain/libdto-cpp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/TrueBrain/libdto-cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TrueBrain%2Flibdto-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TrueBrain%2Flibdto-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TrueBrain%2Flibdto-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TrueBrain%2Flibdto-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TrueBrain","download_url":"https://codeload.github.com/TrueBrain/libdto-cpp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TrueBrain%2Flibdto-cpp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267354529,"owners_count":24073779,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T13:42:17.402Z","updated_at":"2025-07-27T12:05:18.891Z","avatar_url":"https://github.com/TrueBrain.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LibDTO C++\n\nA very simple proof-of-concept how to make a DTO library that can convert JSON to a C++ struct and back.\n\n## Why does this exist?!\n\nAfter seeing some examples on the Internet about how one could make a DTO library in C++, I got curious why they are all very complicated to follow.\nSo I gave it a spin myself.\n\n`boost::json` has a pretty nice templated way to convert JSON to a struct and back.\nThe downside of this approach is that the information is three times in memory:\n- The raw JSON string.\n- The boost converted object.\n- The actual struct.\n\nSo by using `boost::json` there seems to be some overhead in terms of memory.\n\nBy using `boost::json`, it turned out it was relative easy to convert a DTO to JSON and back.\nJust you had to repeat the members of the struct in various of places, making adding new structs a bit annoying.\n\nAs I was using boost anyway, I looked at `boost::hana`, which allows for iterating the members of a struct.\nThis turned out to be a pretty nifty solution, and avoided code duplication.\nThe only penalty is that you need an extra line of code after each struct to let `boost::hana` do its magic.\nLastly, the `BOOST_HANA_ADAPT_STRUCT` has to be done on the global level, making the code look slightly off.\n\nOne could opt for `BOOST_HANA_DEFINE_STRUCT`, but that makes the structs harder to read for everyone.\n\nLastly, I wanted to have a clean way to serialize/deserialize to JSON, but allow future expansion into YAML, protobuf, ...\nAs such, I opt'd for a `serialize::json` namespace, which takes away the slight magic around JSON serialization with `boost::json`.\n\nOne can argue that `serialize/json.hpp` should be two files, but that is bikeshedding.\n\n## Compiling\n\nInstall boost 1.75+.\nRun:\n\n```bash\ng++ -std=c++17 -o dto main.cpp\n```\n\nUse `-I \u003cboostpath\u003e` if you don't have the installed boost in your default include path.\nNow simply run `./dto`, and see that it actually works.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftruebrain%2Flibdto-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftruebrain%2Flibdto-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftruebrain%2Flibdto-cpp/lists"}