Refactor serializers to write to a stream instead of returning a string