Skip to content
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

Determine the type from error message. #720

Closed
MattiasEppler opened this issue Aug 30, 2017 · 11 comments
Closed

Determine the type from error message. #720

MattiasEppler opened this issue Aug 30, 2017 · 11 comments

Comments

@MattiasEppler
Copy link

I get the erros
"could not find to_json() method in T's namespace"
"could not find from_json() method in T's namespace"

but I do not know for which type the methods are not found. How do I get this information?

@MattiasEppler MattiasEppler changed the title Determine the type on error message. Determine the type from error message. Aug 30, 2017
@theodelrieu
Copy link
Contributor

I assume you're using Visual Studio, which doesn't show a stack trace after the static_assert. I have to add that for 3.0.

Meanwhile you can modify json.hpp yourself:

// Somewhere in nlohmann::detail
struct from_json_fn {
static void call(T arg) {
  arg.show_me_the_type();
}
};

Do the same inside to_json_fn and that should help you to debug.

@MattiasEppler
Copy link
Author

Hi. Yes i use Visual studio. Ok thanks for the information.

Do I have to add this

static void call(T arg) {
arg.show_me_the_type();
}

inside "struct from_json_fn"

or just the arg.show_me_the_type(); to the existing call?

@theodelrieu
Copy link
Contributor

Sorry I was on my phone, so hard to be explicit. You have to add it to the existing call, the one with the static_assert.

@MattiasEppler
Copy link
Author

Sorry.

this one:

    template<typename BasicJsonType, typename T>
    void call(const BasicJsonType&, T&, priority_tag<0>) const noexcept
    {
        static_assert(sizeof(BasicJsonType) == 0,
                      "could not find from_json() method in T's namespace");
    }

where to find the arg?

@theodelrieu
Copy link
Contributor

You have to add it:

void call(const BasicJsonType&, T& arg, priority_tag<0>) const noexcept

@MattiasEppler
Copy link
Author

Oh... I missed this :-)
ok.. now I get an error, 'show_me_the_type' is not a member of 'MyTpeToSerialize'.
Is this the trick?

@theodelrieu
Copy link
Contributor

Yes it is. I have this in my TODO list, it will be done in 3.0 by default.

@MattiasEppler
Copy link
Author

Hm ok. But I do not understand why arg.show_me_the_type(); is only called if the static_assert is false.

@theodelrieu
Copy link
Contributor

In fact, this call overload is only called if you forgot to add a from/to_json method.
That's why the static_assert in this overload does a sizeof(T) == 0 check, that will always fail, this can be seen as the "failure" overload.

@MattiasEppler
Copy link
Author

Ok. Thanks for the Explanation.

@nlohmann
Copy link
Owner

@theodelrieu Thanks a lot for taking care of this issue!

@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation and removed solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Aug 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants