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

could not find from_json() method in T's namespace #839

Closed
BrunoLogan opened this issue Nov 21, 2017 · 2 comments
Closed

could not find from_json() method in T's namespace #839

BrunoLogan opened this issue Nov 21, 2017 · 2 comments

Comments

@BrunoLogan
Copy link

BrunoLogan commented Nov 21, 2017

Using the code from the develop branch. I get the error "could not find from_json() method in T's namespace" even when the functions are declared and implemented.

Here's an example:
the error occurs on this line:

vector<Serial::serial_chunk> chunks = curr["serialChunks"].get<vector<Serial::serial_chunk>>();

the struct is:

struct serial_chunk {

        int start;
        int length;
        MeaningType meaning;

        void to_json(json& j, const serial_chunk& sc) {
            j = json{{"start", sc.start}, {"length", sc.length}, {"meaning", sc.meaning}};
        }
        
        void from_json(const json& j, serial_chunk& sc) {
            sc.start = j.at("start").get<int>();
            sc.length = j.at("length").get<int>();
            sc.meaning = j.at("meaning").get<MeaningType>();
        }
    };

MeaningType is an enum.
This struct declaration occurs inside the header file of a class as a public member.
I tried define the methods in a class as well and I get the same error. I'm using Xcode 9.1.

@gregmarr
Copy link
Contributor

Those methods MUST be in your type's namespace (which can be the global namespace), or the library will not be able to locate them (in this example, they are in namespace ns, where person is defined).

They must be free functions in the namespace of your class/struct, not class members.

@BrunoLogan
Copy link
Author

Thanks. I misunderstood. I thought they should be inside the same namespace of the type but that they could be member functions as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants