[ 
https://issues.apache.org/jira/browse/AVRO-2194?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16525102#comment-16525102
 ] 

Eva Krejcirova commented on AVRO-2194:
--------------------------------------

Thanks for the code but unfortunately this doesn't help us much. We are writing 
a library which uses GenericRecord in its API and we don't have control over 
how the objects are created (they are created by the user). Is there any reason 
why the conversion is not added by default? In current situation the behaviour 
of generic and specific API is inconsistent.

> GenericRecord and specific class return different java type for the same 
> field with logicalType
> -----------------------------------------------------------------------------------------------
>
>                 Key: AVRO-2194
>                 URL: https://issues.apache.org/jira/browse/AVRO-2194
>             Project: Avro
>          Issue Type: Bug
>          Components: java, logical types
>    Affects Versions: 1.8.2
>            Reporter: Eva Krejcirova
>            Priority: Major
>         Attachments: avrotest.zip
>
>
> I have an Avro schema which contains field with logical type 
> timestamp-millis. When I deserialize  an object with this schema from json to 
> GenericRecord, I get Long as type of this field. When I deserialize it to 
> specific class, I get DateTime. This prevents me to write a generic code 
> which would handle both cases (I would expect this to be possible since the 
> generated class implements GenericRecord interface).
> E.g.
> {code:java}
> final GenericRecord timestampGenericRecord = 
> readJsonGeneric("timestamptest.json", schema);
> final TimestampTest timestampTestIn = readJson("timestamptest.json", 
> timestampTestOut.getClass(), schema);
> System.out.println("------------ Generic record --------------");
> printTimestamp(timestampGenericRecord);
> System.out.println("------------ Specific record --------------");
> printTimestamp(timestampTestIn);
> ----
> private static void printTimestamp(GenericRecord record) {
>    System.out.println(record);
>    System.out.println(record.get("timestampDateTime").getClass());
> }{code}
> prints out:
> {code:java}
> ------------ Generic record --------------
> {"timestampLong": 1530023620474, "timestampDateTime": 1530023620478}
> class java.lang.Long
> ------------ Specific record --------------
> {"timestampLong": 1530023620474, "timestampDateTime": 
> 2018-06-26T14:33:40.478Z}
> class org.joda.time.DateTime
> {code}
> I am attaching sample code which demonstrates the problem.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to