Added generic object encoder (using serialization).