GreenDelta / olca-ipc.py

Mozilla Public License 2.0
29 stars 17 forks source link

.from_json returns None #1

Closed ezrakahn closed 7 months ago

ezrakahn commented 5 years ago

First of all, really enjoying this package, thank you!

I am not sure I understand how to use the from_json method. I would expect it would return an olca.schema object but it doesn't seem to return anything. Am I missing something? Below is an example of what I am trying to do.

category = next(iter(client.get_all(olca.Category))) 
cat_json = category.to_json() 
olca_cat = olca.Category().from_json(cat_json) 

print(olca_cat)

>> None
ezrakahn commented 5 years ago

Reading the class definition it seems to be behaving as written, but I do not understand the purpose of this method. Thanks in advance for your help!

msrocka commented 5 years ago

Right, it would be good if from_json would return the instance on which it was called. (For the next version, it would be even better when from_json would be a static method so that the example would look like this: olca_cat = olca.Category.from_json(json_dict)). However, currently the usage is like this:

# create an instance
olca_cat = olca.Category()
# fill the instance with data from a dictionary
olca_cat.from_json(json_dict) 
# then you can use it
print(olca_cat.name)
ezrakahn commented 5 years ago

Got it, Thanks!