Simplify PySpark custom serializer logic and API.