Marshmallow: Dict of nested Schema
<p>I'm wondering how to serialize a dict of nested <code>Schema</code>.</p>

<p>Naively, I would expect syntaxes like this to work:</p>

<pre><code>fields.List(Schema)
fields.Dict(Schema)
</code></pre>

<p>or maybe</p>

<pre><code>fields.List(fields.Nested(Schema))
fields.Dict(fields.Nested(Schema))
</code></pre>

<p>Serializing a list of <code>Schema</code> can be achieved through <code>Nested(Schema, many=True)</code>, but I don't know about a <code>dict</code> of <code>Schema</code>.</p>

<p>Assume, for example's sake, that my object is defined like this:</p>

<pre><code>from marshmallow import Schema, fields, pprint

class AlbumSchema(Schema):
    year = fields.Int()

class ArtistSchema(Schema):
    name = fields.Str()

    # What should I write, here?

    # This won't work
    albums = fields.Nested(AlbumSchema(), many=True)

    # If I write this, AlbumSchema is ignored, so this is equivalent to
    albums = fields.Dict(AlbumSchema(), many=True)
    # this, which is not satisfying (AlbumSchema unused)
    albums = fields.Dict()
    # This is not the way either
    albums = fields.Dict(fields.Nested(AlbumSchema))


album_1 = dict(year=1971)
album_2 = dict(year=1970)
bowie = dict(name='David Bowie',
             albums={
                 'Hunky Dory': album_1,
                 'The Man Who Sold the World': album_2
             }
        )

schema = ArtistSchema()
result = schema.dump(bowie)
pprint(result.data, indent=2)
</code></pre>

<p>I expect my object to be serialized as </p>

<pre><code>{ 'albums': { 'Hunky Dory': {'year': 1971},
              'The Man Who Sold the World': {'year': 1970}},
  'name': 'David Bowie'}
</code></pre>

<p>(Question also discussed <a href="https://github.com/marshmallow-code/marshmallow/issues/483" rel="noreferrer">on GitHub</a>.)</p>