Field check while serialization/deserialization #3954
Unanswered
alperyazir
asked this question in
Q&A
Replies: 1 comment
-
This may help: #2356 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello All,
I couldn't find a proper solution. I am wondering that is there a way to field check while serialization.
For example:
namespace ns { struct person { string name; string address; int age; }; NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(person, name, address, age) }
with the macro that helps to create to_json() / from_json() automatically. And we can convert literal JSON data into a struct.
json j = R"({"name": "myname", "address":"myaddress", "age":42})"_json;
At this point, I would like to mark any field such as "name" as a required parameter. And If the name is not provided, I want to get an exception or smh else. Any idea to achieve this?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions