the-other-tim-brown commented on code in PR #10943: URL: https://github.com/apache/hudi/pull/10943#discussion_r1545880874
########## 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: > So when the transformed JSON string got converted back into avro, the schema could change right? The case here is when you have some data and are trying to convert it to avro and it fails. https://github.com/apache/hudi/blob/master/hudi-utilities/src/main/java/org/apache/hudi/utilities/streamer/HoodieStreamerUtils.java#L164 -- 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: commits-unsubscr...@hudi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org