protobuf-java-format icon indicating copy to clipboard operation
protobuf-java-format copied to clipboard

JsonFormat.printToString() does not respect JsonFormat.setDefaultCharset()

Open tonicsoft opened this issue 7 years ago • 0 comments

Implementation of JsonFormat.printToString() (which is in ProtobufFormatter.java) is to print to a byte array using the Charset specified by JsonFormat.setDefaultCharset(), but converts the byte array back to a string using ByteArrayOutputStream.toString(), which uses Charset.defaultCharset().

Conversion from the ByteArrayOutputStream back to a string, https://github.com/bivas/protobuf-java-format/blob/master/src/main/java/com/googlecode/protobuf/format/ProtobufFormatter.java#L91, should also use the specified Charset instead of JVM default.

It is worth pointing out that conversion to bytes and back to string is not actually required if all we want to do is serialize JSON to a java.lang.String.

tonicsoft avatar Sep 19 '16 12:09 tonicsoft