Fixed bug where the wrong type was used when serializing entityMetadata

This fixes a pretty big bug that made writing entityMetadata not work properly.