Some peculiarities of Avro that are worth knowing

Bernd

October 31, 2019

In a previous post we spoke about Avro and how we started to use it together with our REST API based micro services. As it soon turned out, this tool also has some corners and edges, which are advantageous to know. Using the default configuration we found an issue working with Maps used in the generated code.

In regard to this it is important to know that out of the box Avro (we currently use version 1.8.2)

  • uses CharSequence for Strings (apparently to provide backward compatibility)
  • uses Utf8 Classes for string representation internally


This caused some problems for us, e.g. retrieving values by key from Maps did not work in a straight forward way anymore.


We resolved these problems by configuring Avro to use String instead of CharSequence in the configuration of the avro-maven-plugin used in out Maven build.


   <plugin>
       <groupId>org.apache.avro</groupId>
       <artifactId>avro-maven-plugin</artifactId>
       <version>1.8.2</version>
       <executions>
           <execution>
               <id>schemas</id>
               <phase>generate-sources</phase>
               <goals>
                   <goal>schema</goal>
               </goals>
               <configuration>
                  <stringType>String</stringType>
                   <sourceDirectory>${project.basedir}/src/main/avro</sourceDirectory>
               ...


Conclusion

With the configuration change described above we are now able to use Avro in a way fitting all of our requirements in development.

See also:

Bernd

Bernd

Working as a software engineer for many years mostly in the JVM environment