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

How can I write from_json for a complex datatype that is not default constructible? #1115

Closed
shikhartanwar opened this issue May 30, 2018 · 2 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@shikhartanwar
Copy link

shikhartanwar commented May 30, 2018

Hi. This is more of a question rather than a issue.

I have a requirement where I need to create objects from serialized json (serialized using this library only) but those types are not default constructible. I went through the section regarding get() for non-default constructible/non-copyable types but wasn't sure as to how am I supposed to use it for a complex datatype.

Can you please help?

@theodelrieu
Copy link
Contributor

Do you have a small piece of code? What did you try?

Basically you have to open up the namespace nlohmann in your own code, as shown in the section you linked:

namespace mylib
{
struct complex_type
{
  complex_type() = delete;
};
}

namespace nlohmann
{
template <>
struct adl_serializer<mylib::complex_type>
{
  // ... proceed as shown in the section
};
}

@nlohmann nlohmann added kind: question state: needs more info the author of the issue needs to provide more details labels May 30, 2018
@shikhartanwar
Copy link
Author

Thanks a lot. I was able to get it to work.

@nlohmann nlohmann added solution: proposed fix a fix for the issue has been proposed and waits for confirmation kind: question and removed kind: question state: needs more info the author of the issue needs to provide more details labels May 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants