When calling the serializer from the Tree, pass the already calculated key in

I also moved key calculation to a shared role to ensure that the Serializer
and Tree always calculate the key for a given data structure in the same way.

I'm not sure if this provides much of a speedup, but it seems a little saner
to reuse the existing key.