the-other-tim-brown commented on code in PR #10943:
URL: https://github.com/apache/hudi/pull/10943#discussion_r1545960527


##########
hudi-common/src/main/java/org/apache/hudi/avro/HoodieAvroUtils.java:
##########
@@ -209,10 +210,18 @@ public static byte[] avroToJson(GenericRecord record, 
boolean pretty) throws IOE
   private static ByteArrayOutputStream avroToJsonHelper(GenericRecord record, 
boolean pretty) throws IOException {
     DatumWriter<Object> writer = new GenericDatumWriter<>(record.getSchema());
     ByteArrayOutputStream out = new ByteArrayOutputStream();
-    JsonEncoder jsonEncoder = 
EncoderFactory.get().jsonEncoder(record.getSchema(), out, pretty);
-    writer.write(record, jsonEncoder);
-    jsonEncoder.flush();
-    return out;
+    try {
+      JsonEncoder jsonEncoder = 
EncoderFactory.get().jsonEncoder(record.getSchema(), out, pretty);
+      writer.write(record, jsonEncoder);
+      jsonEncoder.flush();
+      return out;
+    } catch (ClassCastException | NullPointerException ex) {
+      // NullPointerException will be thrown in cases where the field values 
are missing
+      // ClassCastException will be thrown in cases where the field values do 
not match the schema type
+      // Fallback to using `toString` which also returns json but without a 
pretty-print option
+      out.write(record.toString().getBytes(StandardCharsets.UTF_8));

Review Comment:
   Ok, I'm not familiar with that flow. If this is breaking that flow, I can 
just make a new method



-- 
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.

To unsubscribe, e-mail: [email protected]

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

Reply via email to