EiTaNBaRiBoA / JsonClassConverter

Simplify your JSON and class interactions! jsonClassConverter effortlessly stores JSON data, converts between JSON and class objects, and instantly loads JSON into usable classes. Streamline your development and data handling with this essential tool.
MIT License
42 stars 2 forks source link

Json to class does not seem to support inheritance #5

Closed herve-ch closed 1 week ago

herve-ch commented 1 week ago

Hello

I tried to serialize a class with a member that inherit another class but when using json to class, the inherited class will be lost (will only be the superclass) I dont know if it's fixable since you use typedef in class for deserializing? The json file has the correct child class in it tho

Thanks

EiTaNBaRiBoA commented 1 week ago

Could you give me a code example that shows the problem? It would really help me understand what's going on. Please include any important details or steps to reproduce the issue. Thanks!

herve-ch commented 1 week ago

ok I'll try to make a mini project and post here

herve-ch commented 1 week ago

TestSerializeJson.zip

Here is a mini project, I want to save a class with a property that inherits a superclass (MyChildClass). I save it in json, when I get it back the Save Class, it property is of type MySuperClass

EiTaNBaRiBoA commented 1 week ago

TestSerializeJson.zip

Here is a mini project, I want to save a class with a property that inherits a superclass (MyChildClass). I save it in json, when I get it back the Save Class, it property is of type MySuperClass

Where is the code?

herve-ch commented 1 week ago

test-serialize-json-project.zip

Oops sorry here is the project

EiTaNBaRiBoA commented 1 week ago

It does work. image

herve-ch commented 1 week ago

the test member is of type MySuperClass. I created it with Type MyChildClass

var child_class:MyChildClass = MyChildClass.new() child_class.my_child_prop="child_prop" child_class.my_super_prop="super_prop" save.test=child_class

In your screenshot test member has only super prop member, I lost the my_child_prop

Save file in json is correct: { "ScriptName": "Save", "test": { "ScriptName": "MyChildClass", "my_child_prop": "child_prop", "my_super_prop": "super_prop" } }

test should be of type MyChildClass

EiTaNBaRiBoA commented 1 week ago

the test member is of type MySuperClass. I created it with Type MyChildClass

var child_class:MyChildClass = MyChildClass.new() child_class.my_child_prop="child_prop" child_class.my_super_prop="super_prop" save.test=child_class

In your screenshot test member has only super prop member, I lost the my_child_prop

Got it! The child_class is set up as the inherited class, but in save.gd it's supposed to be MySuperClass. Thanks for spotting this!

herve-ch commented 1 week ago

no problem lol good luck and thx for this great tool!

herve-ch commented 1 week ago

the test member is of type MySuperClass. I created it with Type MyChildClass var child_class:MyChildClass = MyChildClass.new() child_class.my_child_prop="child_prop" child_class.my_super_prop="super_prop" save.test=child_class In your screenshot test member has only super prop member, I lost the my_child_prop

Got it! The child_class is set up as the inherited class, but in save.gd it's supposed to be MySuperClass. Thanks for spotting this!

Wait i dont Know if I understand well but for me, the save file is correct. The json to class should return the inherited class MyChildClass And not the superclass.

EiTaNBaRiBoA commented 1 week ago

the test member is of type MySuperClass. I created it with Type MyChildClass var child_class:MyChildClass = MyChildClass.new() child_class.my_child_prop="child_prop" child_class.my_super_prop="super_prop" save.test=child_class In your screenshot test member has only super prop member, I lost the my_child_prop

Got it! The child_class is set up as the inherited class, but in save.gd it's supposed to be MySuperClass. Thanks for spotting this!

Wait i dont Know if I understand well but for me, the save file is correct. The json to class should return the inherited class MyChildClass And not the superclass.

I made a fix, try updating your jsonclassconverter to match the last commit, and let me know if it works now. Here

herve-ch commented 1 week ago

the test member is of type MySuperClass. I created it with Type MyChildClass var child_class:MyChildClass = MyChildClass.new() child_class.my_child_prop="child_prop" child_class.my_super_prop="super_prop" save.test=child_class In your screenshot test member has only super prop member, I lost the my_child_prop

Got it! The child_class is set up as the inherited class, but in save.gd it's supposed to be MySuperClass. Thanks for spotting this!

Wait i dont Know if I understand well but for me, the save file is correct. The json to class should return the inherited class MyChildClass And not the superclass.

I made a fix, try updating your jsonclassconverter to match the last commit, and let me know if it works now. Here

Thanks!! will try when i get home

Thanks a lot