Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.8.2
-
None
-
None
Description
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.
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()); }
prints out:
------------ 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
I am attaching sample code which demonstrates the problem.