Use toString() and Text.of() for serialization.
toString()
Convert the document to an array of lines (which can be deserialized again via Text.of).