@Test public void testHashCodeNotReset() throws NoSuchFieldException, IllegalAccessException { IndexedRecord avroRecord = createAvroRecord(); byte[] bytes = avroSerializer.serialize("topic", avroRecord); IndexedRecord deserialized1 = (IndexedRecord) deserializer.deserializeWithSchemaAndVersion( "topic", false, bytes).container(); int hashCode = deserialized1.getSchema().hashCode(); IndexedRecord deserialized2 = (IndexedRecord) deserializer.deserializeWithSchemaAndVersion( "topic", false, bytes).container(); assertThat(deserialized1.getSchema(), sameInstance(deserialized2.getSchema())); org.apache.avro.Schema avroSchema = deserialized2.getSchema(); assertThat(getSchemaInternalHashCode(avroSchema), equalTo(hashCode)); }
protected GenericContainerWithVersion deserializeWithSchemaAndVersion( String topic, boolean isKey, byte[] payload) throws SerializationException { if (payload == null) { return null; } DeserializationContext context = new DeserializationContext(topic, isKey, payload); AvroSchema schema = context.schemaForDeserialize(); Object result = context.read(schema.rawSchema(), null); try { Integer version = schemaVersion(topic, isKey, context.getSchemaId(), context.getSubject(), schema, result); if (schema.rawSchema().getType().equals(Schema.Type.RECORD)) { return new GenericContainerWithVersion((GenericContainer) result, version); } else { return new GenericContainerWithVersion(new NonRecordContainer(schema.rawSchema(), result), version); } } catch (RestClientException | IOException e) { throw new SerializationException("Error retrieving Avro " + getSchemaType(isKey) + " schema version for id " + context.getSchemaId(), e); } }
AbstractKafkaAvroDeserializer extends AbstractKafkaSchemaSerDe { protected GenericContainerWithVersion deserializeWithSchemaAndVersion( String topic, boolean isKey, byte[] payload) throws SerializationException { if (payload == null) { return null; } DeserializationContext context = new DeserializationContext(topic, isKey, payload); AvroSchema schema = context.schemaForDeserialize(); Object result = context.read(schema.rawSchema(), null); try { Integer version = schemaVersion(topic, isKey, context.getSchemaId(), context.getSubject(), schema, result); if (schema.rawSchema().getType().equals(Schema.Type.RECORD)) { return new GenericContainerWithVersion((GenericContainer) result, version); } else { return new GenericContainerWithVersion(new NonRecordContainer(schema.rawSchema(), result), version); } } catch (RestClientException | IOException e) { throw new SerializationException("Error retrieving Avro " + getSchemaType(isKey) + " schema version for id " + context.getSchemaId(), e); } } }
AbstractKafkaAvroDeserializer extends AbstractKafkaSchemaSerDe { protected GenericContainerWithVersion deserializeWithSchemaAndVersion( String topic, boolean isKey, byte[] payload) throws SerializationException { if (payload == null) { return null; } DeserializationContext context = new DeserializationContext(topic, isKey, payload); AvroSchema schema = context.schemaForDeserialize(); Object result = context.read(schema.rawSchema(), null); try { Integer version = schemaVersion(topic, isKey, context.getSchemaId(), context.getSubject(), schema, result); if (schema.rawSchema().getType().equals(Schema.Type.RECORD)) { return new GenericContainerWithVersion((GenericContainer) result, version); } else { return new GenericContainerWithVersion(new NonRecordContainer(schema.rawSchema(), result), version); } } catch (RestClientException | IOException e) { throw new SerializationException("Error retrieving Avro " + getSchemaType(isKey) + " schema version for id " + context.getSchemaId(), e); } }  }
AbstractKafkaAvroDeserializer extends AbstractKafkaSchemaSerDe { protected GenericContainerWithVersion deserializeWithSchemaAndVersion( String topic, boolean isKey, byte[] payload) throws SerializationException { if (payload == null) { return null; } DeserializationContext context = new DeserializationContext(topic, isKey, payload); AvroSchema schema = context.schemaForDeserialize(); Object result = context.read(schema.rawSchema(), null); try { Integer version = schemaVersion(topic, isKey, context.getSchemaId(), context.getSubject(), schema, result); if (schema.rawSchema().getType().equals(Schema.Type.RECORD)) { return new GenericContainerWithVersion((GenericContainer) result, version); } else { return new GenericContainerWithVersion(new NonRecordContainer(schema.rawSchema(), result), version); } } catch (RestClientException | IOException e) { throw new SerializationException("Error retrieving Avro " + getSchemaType(isKey) + " schema version for id " + context.getSchemaId(), e); } }   }
AbstractKafkaAvroDeserializer extends AbstractKafkaSchemaSerDe { protected GenericContainerWithVersion deserializeWithSchemaAndVersion( String topic, boolean isKey, byte[] payload) throws SerializationException { if (payload == null) { return null; } DeserializationContext context = new DeserializationContext(topic, isKey, payload); AvroSchema schema = context.schemaForDeserialize(); Object result = context.read(schema.rawSchema(), null); try { Integer version = schemaVersion(topic, isKey, context.getSchemaId(), context.getSubject(), schema, result); if (schema.rawSchema().getType().equals(Schema.Type.RECORD)) { return new GenericContainerWithVersion((GenericContainer) result, version); } else { return new GenericContainerWithVersion(new NonRecordContainer(schema.rawSchema(), result), version); } } catch (RestClientException | IOException e) { throw new SerializationException("Error retrieving Avro " + getSchemaType(isKey) + " schema version for id " + context.getSchemaId(), e); } }    }