Eva Krejcirova created AVRO-2194:
------------------------------------

             Summary: 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
         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