-
Notifications
You must be signed in to change notification settings - Fork 0
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
Problem with optional fields is not solved #6
Comments
Addition: I looked in metaprograming code in TgTypeParser.h, I think this serializers don't help the issue. Am I wrong? is_initialized_with_default_constructor_v |
I've made some research, how resulting json is generated, and found that json.put() uses heuristic hacks depended of value type to determine, include field to resulting json or not. It can generate incorrect results sometimes:
Lack of possibility to include false for bool value, 0 for int value to resulting json is not good. |
I guess this is easily fixable
For this, I'll probably have to think how-to |
It should be fixed now as I wrapped really optional objects under std optional, can you try it? |
I'm experimenting with optional attributes here reo7sp#320, keep an eye there too. Also wanted to add OptionalEmptyString<>, OptionalFalseBool<> attributes, but don't know how to differentiate it from Required types. |
Meh, the one without jsoncpp is a mess, as i said before, doesn't work (gives a bad request) for createStickerSet or setBotCommands(Windows) etc, (Why even manually concat json string when there is jsoncpp or even nlohmann/json which is header only?) So I'm not interested.
And I think they should be wrapped in a empty struct tag, so they can be figured out with metaprogramming. My updated code with std::optional doesn't enforce the required parameters to be set, but it will indeed put the required args in JSON now, so I think mine is the best solution. |
As I see, your fork doesn't solve the problem with optional fields in api structures and json.
Let's see.
Ok, we can remove LinkPreviewOptions structure from output json COMPLETELY when it null.
We cannot include only a PART of LinkPreviewOptions structure in output json. Thats why I suggest wrapping fields in boost::optional.
It's possible to check optionality from pointer field, but we cannot make optional bools, ints or strings (ok, strings - disputable).
Need to skip chatId.
ChatId is always serialized as 0 if it was not assigned implicitly.
The text was updated successfully, but these errors were encountered: