def to_data(self, obj, partitioning_strategy=None):
if obj is None:<EOL><INDENT>return None<EOL><DEDENT>if isinstance(obj, Data):<EOL><INDENT>return obj<EOL><DEDENT>out = self._create_data_output()<EOL>try:<EOL><INDENT>serializer = self._registry.serializer_for(obj)<EOL>partitioning_hash = self._calculate_partitioning_hash(obj, partitioning_strategy)<EOL>out.write_int_big_endian(partitioning_hash)<EOL>out.write_int_big_endian(serializer.get_type_id())<EOL>serializer.write(out, obj)<EOL>return Data(out.to_byte_array())<EOL><DEDENT>except:<EOL><INDENT>handle_exception(sys.exc_info()[<NUM_LIT:1>], sys.exc_info()[<NUM_LIT:2>])<EOL><DEDENT>finally:<EOL><INDENT>pass<EOL><DEDENT>
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