Serialize function that's recursive