Serialize an object and its relations through class definitions