If you specify "order" : "ignore" in a field then it won't be considered by hashCode or equals. Processing also won't descend into the value of that field, speeding things up.
Doug On Nov 29, 2017 1:15 AM, "Tushar Gosavi" <[email protected]> wrote: > 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 > Question > schema. By default, the generated class inherit hashCode and equals from > SpecificRecordBase > 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 > this? > > Thanks & Regards, > -Tushar. >
