4

As per the answer in Generate Avro Schema from certain Java Object, it's possible to use Reflection to convert from a Java POJO to an Avro schema.

One could manually do something along the lines of:

Schema schema = ReflectData.get().getSchema(POJO.class);
File schemaFile = new File("pojo-reflected.avsc");
FileWriter fileWriter = new FileWriter(schemaFile);
fileWriter.append(schema.toString(true));
fileWriter.close();

But does anyone know of any plugins that have the capability to do this? The confluent schema registry plugin doesn't provide any relevant functionality, and while there is an avro maven plugin, it seems to be more so geared towards the inverse: generating Java code from schemas rather than vice versa.

I could probably hack together a solution along the lines of the answer in Generating sources by running a project's java class in Maven and use a Java class to generate the schemas, but I feel like a plugin would be cleaner.

TyrusB
  • 83
  • 8

0 Answers0