[SPARK-3045] Make Serializer interface Java friendly