i'm not sure whether this really quite fits what you are looking for, but
Orlando by Virginia Woolf comes to mind. it's a roman à clef, meaning she is writing about real people disguising them with different names (Orlando is based on Woolf's friend Vita Sackville-West), and to escape the censorship of the time the main character of the book is a man at the time he has a love affair with a woman, but later is transformed into a woman.