-
-
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
NLOHMANN_DEFINE_TYPE_INTRUSIVE with nlohmann::json::json_pointer #4104
Comments
This issue has been marked as stale because it has been open for 90 days without activity. If this issue is still relevant, please add a comment or remove the "stale" label. Otherwise, it will be closed in 10 days. Thank you for helping us prioritize our work! |
The |
@gregmarr #include <nlohmann/json.hpp>
#include <string>
#include <cstdio>
namespace nlohmann {
inline void to_json(json& j, const json::json_pointer& crj)
{
j = json(crj.to_string());
}
inline void from_json(const json& cj, json::json_pointer& rj)
{
rj = nlohmann::json::json_pointer(cj.get<std::string>());
}
}
struct Test {
nlohmann::json::json_pointer ptr;
nlohmann::json value;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Test, ptr, value);
};
// Type your code here, or load an example.
int main() {
Test test{.ptr = nlohmann::json::json_pointer("/test"), .value = 10};
nlohmann::json jtest = test;
printf("jtest=%s\n", jtest.dump().c_str());
} The remaining question is if it would make sense to have these conversions in the library instead. |
I'm not sure it's obvious that everyone would want this represented in their JSON as a plain string. |
It is basically an analogy to |
It's really @nlohmann's call. It might make sense for there to be a default here. The only reason I wasn't sure is that it could be reference to something in the JSON itself, and it would change based on where in the tree you did a |
@gregmarr I am not sure I am following you. For me |
I mean you have a JSON file that has the object
Again, I think this is something that can likely be ignored for the common case. |
Description
Using
NLOHMANN_DEFINE_TYPE_INTRUSIVE
(or non-intrusive) macro to define conversions for struct withnlohmann::json::json_pointer
member fails to compile (MSVC v19.3 - VS 2022), with or without explicit conversion.Reproduction steps
Compile the sample code.
Here is a Godbolt link https://godbolt.org/z/fdrPrcT7T
Expected vs. actual results
Expecting it will compile.
Minimal code example
Error messages
Compiler and operating system
MSVC v19.3 - VS 2022
Library version
3.11.2
Validation
develop
branch is used.The text was updated successfully, but these errors were encountered: