Thursday, April 29, 2021

Avsc to Pojo generate with maven project

Avro schemas are defined using JSON and let see how we can generate POJO. Here I have used maven and we can play the same with gradle also. 



Maven Dependencies

The below dependencies need to add.


We can provide the source directory and output directory directly into maven. So that we can avoid some boilerplate code in java class.





After set upping this pom, now you can place your avsc file into the methined location the pom.xml. Once you place this execute the maven command which is mvn generate-sources. No the genearting from schema to pojo process will happen. After that we have play aroung our POJO like setting data etc.,. 

Now the project structure is below format. It may differ in eclipse. I am using intellij.



Dont create entity manually. It will be generated automatically. Now its time to write final code here.





Now just run the above program and get the below output. 



From the above output you can get all details. Thats it. Have fun...