Tried below but get a null pointer exception
public static String getJson(GenericRecord genericRecord) throws IOException {
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
final JsonEncoder encoder =
EncoderFactory.get().jsonEncoder(genericRecord.getSchema(), out);
SpecificDatumWriter<GenericRecord> writer = new SpecificDatumWriter<>();
writer.getSpecificData().addLogicalTypeConversion(new
TimeConversions.TimestampConversion());
writer.write(genericRecord, encoder);
return out.toString();
}
}
On Thu, Aug 23, 2018 at 1:06 AM kant kodali <[email protected]> wrote:
> Hi All,
>
> I have a Generic Record with timestamp columns and I want to convert the
> entire generic record to Json so I tried genericrecord.toString() and the
> timestamp columns in json output has milliseconds how I am trying to see if
> there is an easy way where the JSON output can have *2018-06-29
> 00:36:27.678* for timestamp columns in Generic Record?
>
> Thanks!
>