title: Serialize and deserialize objects from user-defined classes
body: <p>Suppose I have class hierarchy like this:</p>
  
  <pre><code>class SerializableWidget(object):
  # some code
  
  class WidgetA(SerilizableWidget):
  # some code
  
  class WidgetB(SerilizableWidget):
  # some code
  </code></pre>
  
  <p>I want to be able to serialize instances of <code>WidgetA</code> and <code>WidgetB</code> (and potentially other widgets) to text files as <code>json</code>. Then, I want to be able to deserialize those, without knowing beforehand their specific class:</p>
  
  <pre><code>some_widget = deserielize_from_file(file_path) # pseudocode, doesn't have to be exactly a method like this
  </code></pre>
  
  <p>and <code>some_widget</code> needs to be constructed from the precise subclass of <code>SerilizableWidget</code>. How do I do this? What methods exactly do I need to override/implement in each of the classes of my hierarchy?</p>
  
  <p>Assume all fields of the above classes are primitive types. How do I override some <code>__to_json__</code> and <code>__from_json__</code> methods, something like that?</p>