Hi,

I have two schemas:
V1:

{
  "type" : "record",
  "name" : "TestRecordGroup",
  "namespace" : "com.example",
  "fields" : [ {
    "name" : "testRecord",
    "type" : {
      "type" : "record",
      "name" : "TestRecordV1",
      "fields" : [ {
        "name" : "testStringFieldOld",
        "type" : "string"
      } ]
    }
  } ]
}

V2:

{
  "type" : "record",
  "name" : "TestRecordGroup",
  "namespace" : "com.example",
  "fields" : [ {
    "name" : "testRecord",
    "type" : {
      "type" : "record",
      "name" : "TestRecordV2",
      "fields" : [ {
        "name" : "testStringFieldNew",
        "type" : "string",
        "aliases" : [ "testStringFieldOld" ]
      } ],
      "aliases" : [ "TestRecordV1" ]
    }
  } ]
}


I renamed TestRecordV1 to TestRecordV2, changed the field inside that
record testStringFieldOld to testStringFieldNew and added aliases.
I generated Java classes from schema V1 and V2 using Apache Avro Tools
1.12.0. Then, using a serializer, classes v2, and schema v2, I obtained a
binary message. Next, I tried to deserialize this message using classes v1
and schema v2, and I got the following error:
org.apache.avro.generic.GenericData$Record
cannot be cast to com.example.TestRecordV1. java.lang.ClassCastException:
org.apache.avro.generic.GenericData$Record cannot be cast to
com.example.TestRecordV1.

I realized that when searching for a class, the deserializer doesn't find
the TestRecordV2 class and uses GenericRecord instead. However, logically,
if it can't find the TestRecordV2 class, it should look for the name in the
alias TestRecordV1, and then the class would be found. Could you explain
how to use aliases in the case of renaming a record?

Thanks in advance.

--
All the best,

Anton Aleshin
*Software Engineer*


anton.ales...@gmail.com



-- 
All the best,
Anton Aleshin

+351 913 782 314
anton.ales...@gmail.com

Reply via email to