Fix bug in PrettyPrinter, add roundtrip and idempotency tests

(This also relaxes the requirement on the `Writer` given to the PrettyPrinter to allow `StringWriter`s to be used without having to wrap them in a `BufferedWriter`)