-
-
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
Subclassing json() & error on recursive load #1201
Comments
I haven't tried you code yet, but I fear that the library is currently not designed to be subclassed. You can configure it partly via template arguments, but also by defining translations from and to arbitrary types. |
@Dariusz1989 any update on it ? |
A snap so sorry, I saw the reply and went on with my R&D. I think I ended up just passing json rather than my wrapper to solve this temporary. But I was unable to use my class as a recursive pass sadly. When I have a moment I'll provide a full test example to show how/when it breaks. Perhaps nlohmann or some other smart person will be able to help :- ) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hey
So I have subclassed json with another class so that in future if I want to change the container class/type I can just replace that within my class and not have to go over entire app replacing all containers.
Essentially class looks like this :
Now the issue is when I have a json file I read from file, that has some name/id/etc information + children which is of the same structure.
The initial object load file, but the children throw me an error.
Say if I do
data["name] < this prints name.
if I do data["children"].count() < this gets me proper count
if I do data["children"][0]["name] < this gets me name of child - all great.
But if I try to pass that object to newly created class to configure it. Say child class I get this error :
Essentially loops goes as follow:
Errors starts here:
Its driving me nuts, as far as I debug it, everything is of proper myObject class & have data whenever I print it. But the second I try to generate child from json["children"]array I get an crash :- (
Does this look familiar to any one?
TIA
Btw I have no idea why formating is off ;[
Edit1. Thanks Nlohmann for formating fix! : -)
I also did test with using json, instead of myObject class and everyhing works. So there is a weird issue when I try to load children as my subclass class thini ?
The text was updated successfully, but these errors were encountered: