avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tushar Gosavi <tus...@apache.org>
Subject How to override hashCode/equals on java classes generated by avro.
Date Wed, 29 Nov 2017 09:15:20 GMT
Hi All,

I am creating java objects using Avro Maven plugin, and I have a requirement
to generate hashCode and equals based on specific fields. Is that possible?

For example, I have a schema, Question
  "type" : "record",
  "name" : "Question",
  "namespace" : "com.tugo.questions.schema",
  "fields" : [ {
    "name" : "id",
    "type" : "string",
  }, {
    "name" : "text",
    "type" : "string"
  }, {
    "name" : "type",
    "type" : "string"
  .... // few more fields

I want to generate hashCode and equals based on just the id string in the
schema. By default, the generated class inherit hashCode and equals from
which calls GenericData.hashCode, which iterates over all fields and
compute the hashCode.
This takes a considerable amount of time with the large schema. Any advice
on how to achieve

Thanks & Regards,

View raw message