title: Python: converting class objects to JSON - object is not JSON serializable
body: <p>I have a list of objects in my Python code. Each object is of type Outer with associated Inner objects - the classes are defined like this:</p>
  <pre><code>from decimal import Decimal
  
  @dataclass
  class Inner:
      col_a: Decimal
      col_b: str
      col_c: List['str']
  
  @dataclass
  class Outer:
      col_a: str
      col_b: Decimal
      col_c: List[Inner]
  </code></pre>
  <p>I would like to convert these objects into JSON. As I am using Decimal, I was hoping to just create my own encoder and use it in conjunction with json.dumps():</p>
  <pre><code>class DecimalJsonEncoder(json.JSONEncoder):
      def default(self, obj):
          if isinstance(obj, Decimal):
              return str(obj)
          else:
              return super(DecimalJsonEncoder, self).default(obj)
  </code></pre>
  <p>... and...</p>
  <pre><code>my_json = json.dumps(my_list, cls=DecimalJsonEncoder)
  </code></pre>
  <p>However, when I create a list of Outer objects (my_list) and try to create JSON, I get this error:</p>
  <pre><code>TypeError: Object of type Outer is not JSON serializable
  </code></pre>
  <p>I'm using Python 3.7.</p>
  <p>Thanks in advance for any assistance.</p>