We should put this pattern in a base serializer.