SPARK-3926 [CORE] Result of JavaRDD.collectAsMap() is not Serializable

Make JavaPairRDD.collectAsMap result Serializable since Java Maps generally are
I think that these methods should live in `JavaUtils` rather than in this trait so that they can be used by the Streaming and SQL Java APIs, too.