-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Assertion failure when serializing array with JSON_DIAGNOSTICS set #2926
Comments
I currently fail to reproduce the issue. This is what I have so far: #include <iostream>
#define JSON_DIAGNOSTICS 1
#include "json.hpp"
using json = nlohmann::json;
struct widget
{
std::string name;
int age;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(widget, name, age);
};
void to_json(json& j, const std::optional<widget>& opt)
{
if (opt.has_value())
{
j = *opt;
}
else
{
j = nullptr;
}
}
int main()
{
std::array<std::optional<widget>, 3> widgets {{
std::nullopt, widget{"Jane", 23}, widget{"John", 42}
}};
json j = widgets;
std::cout << j << std::endl;
} Can you share more information on your example? |
@nlohmann Sadly I am using the normal |
That fixes it! Thanks for divining and fixing the root cause @AnthonyVH / @carlsmedstad |
Good to know this is fixed now! |
@nlohmann Do you also need to track capacity in the external
construct
functions, e.g.?
I'm getting a very hard to reproduce write access violation with
JSON_DIAGNOSTICS 1
when implicitly serializing anstd::array
of serializable structs. Can't get a minimal example to throw it though, not sure why. It seems related to this bug though.Thrown here:
One stack up:
Edit: It's actually an array of
std::optional
s with a custom serializer per https://nlohmann.github.io/json/features/arbitrary_types/#how-do-i-convert-third-party-types. This works fine withJSON_DIAGNOSTICS 0
.Originally posted by @MHebes in #2838 (comment)
The text was updated successfully, but these errors were encountered: