GenericRecord is a schema-aware, dynamically accessed container for Avro fields. Unlike a generated specific record, it has no type-specific structure, so consumers inspect fields before reading them. section 3.2.9
A KafkaAvroDeserializer returns GenericRecord when SPECIFIC_AVRO_READER_CONFIG is false. The record still follows the schema and contains the same data, but callers work with it more like a HashMap than a generated Java class. section 3.2.9 section 3.7.1
Read and update fields dynamically:
- Call hasField with the exact schema field name before attempting access. section 3.2.9
- Call get with the schema spelling, such as name, real_name, or movies. section 3.2.9
- Call put to update or set a value, such as genericRecord.put("real_name", "updated name"). section 3.2.9
- Enumerate GenericRecord.getSchema().getFields() when the available structure is unknown. section 3.2.9
Choosing generic versus specific Avro records
A consumer configured with SPECIFIC_AVRO_READER_CONFIG=true can call avenger.getName(), avenger.getRealName(), and avenger.getMovies() on a generated AvroAvenger object. With the setting false, it receives GenericRecord and checks each field before calling get. This trades direct, structure-aware access for flexibility across arbitrary schema-shaped records. section 3.2.9
