-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
value() throws unhandled exception for partially specified json object #2393
Comments
I don't think this is a bug. |
If you know the inner workings that might be logical. But from a user’s perspective it means you can't use My goal is to find an elegant way to update a configuration object (struct) with values from a configuration file.
For instance a new version of the program should be able to add new settings to the configuration object, while still be able to read old configuration files. The only solution I know of that works without side-effects is to use json::find(key) for every key-value. |
The error here is actually happening in
but that doesn't help with the
|
I tried using |
You would indeed need support for this type of processing in the |
I have pretty much the same issue, I added a new config option to my settings class, and now when loading the old json files I am getting an exception because the new config option is not found in the old json.
|
@cristian1980 You can, as I described above, you just need to write
https://gcc.godbolt.org/z/vMjq14 If you really want to keep the macros, you just need a different definition of
or if you really want to keep the
|
@gregmarr Thank you, this is exactly what I needed. Maybe this should be the default mode. |
Not so fast. What if you have more than one instance of baz? |
I consider this a valid solution. Some final thoughts: An idea: |
The current code for
It would need to become something like this:
I don't think the potential extra expense of the |
I guess I'm the odd one out so put a policy class to customize this behavior on my wish list :-) |
json::value(key, default) function throws an unhandled exception if a json object doesn't include every key value pair.
I would expect missing value(s) be taken from provided default.
json:
Please describe the steps to reproduce the issue.
Link to example in Compiler Explorer
Can you provide a small but working code example?
Which compiler and operating system are you using?
Which version of the library did you use?
develop
branchThe text was updated successfully, but these errors were encountered: