MarvinCai commented on a change in pull request #9608:
URL: https://github.com/apache/pulsar/pull/9608#discussion_r577746589



##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericJsonWriter.java
##########
@@ -36,7 +38,11 @@ public GenericJsonWriter() {
     @Override
     public byte[] write(GenericRecord message) {
         try {
-            return 
objectMapper.writeValueAsBytes(((GenericJsonRecord)message).getJsonNode().toString());
+            ByteArrayOutputStream buffer = new ByteArrayOutputStream();

Review comment:
       I wonder if there's any specific reason we want to create our own 
ByteArrayOutputStream & JsonGenerator, which is what 
[objectMapper.writeValueAsBytes()](https://github.com/FasterXML/jackson-databind/blob/7ccdb596ce6ce3389aa5b9824cab70441fd72322/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java#L1699-L1708)
 is doing internally, instead it is using a ByteArrayBuilder which is basically 
Jackson's implementation of OutputStream and claim to be more efficient in many 
of its use case.
   I think we should just use objectMapper.writeValueAsBytes() unless we want 
to write output to somewhere else(not a byte[]).




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to