-
Notifications
You must be signed in to change notification settings - Fork 751
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
detail namespace collision with nlohmann::json? #499
Comments
So this only triggers at runtime on that polymorphic check? Do you have any issues with non-polymoprhic code when using both libraries? |
It looks like I also have a problem with non-polymorphic code: #include <json.hpp>
// #include <cereal/types/polymorphic.hpp>
#include <cereal/archives/binary.hpp>
#include <cereal/access.hpp> //So we can make serialize private so developers aren't tempted to call it.
#include <cereal/types/string.hpp> //This is needed to serialize std::string. There are similar ones for the other std containers
#include <cereal/types/vector.hpp> //This is needed to serialize std::vector. There are similar ones for the other std containers
using namespace std;
class Bug
{
public:
std::string text;
void load(const nlohmann::json & s) {};
private:
friend class cereal::access;
template <class Archive> void serialize(Archive &ar) {ar(text);};
};
int main()
{
Bug obj;
std::ostringstream os;
{
cereal::BinaryOutputArchive oarchive(os);
oarchive(obj);
}
Bug obj2;
std::istringstream is(os.str());
{
cereal::BinaryInputArchive iarchive(is);
iarchive(obj2);
}
return 0;
} Has the following static assertion:
However, if I either:
It magically works |
I've also confirmed that the break occurs when moving from |
Update: I've confirmed it is definitely not a namespace collision. I renamed detail to an arbitrary name and I still see the same problem. Instead, it looks like somehow Cereal thinks the nlohmann::json type is a cereal::Archive such that when passed into a function named load it thinks I am registering a new load/save function. Unfortunately both libraries are extremely template heavy so it's hard to understand what's going on |
Has a fix been found this problem? I'm seeing the same in my code (with the difference being that I am writing load and store functions to serialize a |
I'm seeing a very strange bug when using your library in conjunction with the newest version of https://github.com/nlohmann/json.
Reproduce with the following:
This code, when compiled with the latest
nlohmann::json
throws the following:Curiously, though, it only happens when the name of the function in the
Bug
class isload
, which is why I'm opening an issue with your library (it sseems to have special significance with your library).Again, curiously, compiling against a 2.X version of
nlohmann::json
does not product this exception.I noticed one change from
nlohmann::json
2.X->3.X is the inclusion of thenlohmann::detail
namespace. Could this be somehow conflicting withcereal::detail
? I will also open an issue againstnlohmann::json
.Still trying to figure out root cause
nlohmann::json issue: nlohmann/json#1082
The text was updated successfully, but these errors were encountered: