Generate Java classes from schemas
Generate Java classes from Avro, Protobuf, or JSON Schema files to use with Apache Kafka® and Karapace Schema Registry. These classes match your schema structure and help serialize and deserialize messages with the correct data types.
When to generate data classes
Generate data classes if you:
- Work with schema-based formats such as Avro, Protobuf, or JSON Schema.
- Want strongly typed Kafka producers and consumers.
- Use Karapace as your Schema Registry.
- Prefer Java classes over using generic records or data without a defined schema (such as raw strings or byte arrays).
- Need to enforce data governance in your Kafka topics.
Prerequisites
- An active Aiven for Apache Kafka® service
- Karapace Schema Registry enabled
- Java (JDK 8 or later)
- Apache Maven installed
- A schema file in one of these formats:
- Avro (
.avsc
) - Protobuf (
.proto
) - JSON Schema (
.json
)
- Avro (
Next steps
See schema-specific instructions:
- Generate Avro Java classes with avro-tools
- Generate Protobuf Java classes with protoc
- Generate JSON Schema Java classes with jsonschema2pojo
After generating your classes, use them with Kafka and the schema registry to produce and consume messages.