To/from JSON deprecated in widget

As far as I see, with APIv1 exchanging data to/from json is deprecated at the ModuleWidget level.
However the ModuleWidget owns the Module, not viceversa.
Furthermore, the Module and ModuleWidget constructors execute before the Module::dataFromJson.
What is the best way to store data related to custom widgets in JSON and propagating this to the ModuleWidget?

1 Like

Imagine that your Module is running headless and that a ModuleWidget doesn’t exist. Would the data need to be serialized still? If so, move the serialization to Module::dataToJson. If not, you may override ModuleWidget::toJson and call the superclass’ method.

1 Like

Is there a framework to test headless modules?

Not yet. Maybe in v2 or v3.

Yep the data to be serialized is related to the GUI. If ModuleWidget::toJson for now is ok and will not be deleted until v2 then it could be the right way to do this.

At the end I changed my mind.
I serialized everything in the Module and then added a flag that the Widget checks. If the flag is true, the Widget reads the new value from the Module. This way I don’t override deprecated to/fromJson methods in the Widget and I ensure that everyone knows what’s going on.