code: def _py2java(sc, obj):
      
      if isinstance(obj, RDD):
          obj = _to_java_object_rdd(obj)
      elif isinstance(obj, DataFrame):
          obj = obj._jdf
      elif isinstance(obj, SparkContext):
          obj = obj._jsc
      elif isinstance(obj, list):
          obj = [_py2java(sc, x) for x in obj]
      elif isinstance(obj, JavaObject):
          pass
      elif isinstance(obj, (int, long, float, bool, bytes, unicode)):
          pass
      else:
          data = bytearray(PickleSerializer().dumps(obj))
          obj = sc._jvm.org.apache.spark.mllib.api.python.SerDe.loads(data)
      return obj
docs: Convert Python object into Java