You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by kant kodali <ka...@gmail.com> on 2018/08/23 08:06:01 UTC
Generic Record with timestamp columns to Json date time instead of long
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!
Re: Generic Record with timestamp columns to Json date time instead
of long
Posted by kant kodali <ka...@gmail.com>.
posted here as well
https://stackoverflow.com/questions/51982374/how-to-convert-avro-genericrecord-to-json-using-while-coverting-timestamp-fields
On Thu, Aug 23, 2018 at 1:53 AM kant kodali <ka...@gmail.com> wrote:
> 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 <ka...@gmail.com> 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!
>>
>
Re: Generic Record with timestamp columns to Json date time instead
of long
Posted by kant kodali <ka...@gmail.com>.
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 <ka...@gmail.com> 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!
>