code: def to_data(self, obj, partitioning_strategy=None):
          
          if obj is None:
              return None
  
          if isinstance(obj, Data):
              return obj
  
          out = self._create_data_output()
          try:
              serializer = self._registry.serializer_for(obj)
              partitioning_hash = self._calculate_partitioning_hash(obj, partitioning_strategy)
  
              out.write_int_big_endian(partitioning_hash)
              out.write_int_big_endian(serializer.get_type_id())
              serializer.write(out, obj)
              return Data(out.to_byte_array())
          except:
              handle_exception(sys.exc_info()[1], sys.exc_info()[2])
          finally:
              pass
docs: Serialize the input object into byte array representation
          :param obj: input object
          :param partitioning_strategy: function in the form of lambda key:partitioning_key
          :return: Data object