Search code examples
mavenavro

Avro Maven Plugin: Type not supported


I have a file Pojo.avsc which contains the following declaration:

{
  "namespace": "io.fama.pubsub.schema",
  "type": "record",
  "name": "Pojo",
  "fields": [
    {
      "name": "field",
      "type": "string"
    }
  ]
}

I have a file PojoCollection.avsc which just contains a collection of Pojo objects.

{
  "namespace": "io.fama.pubsub.schema",
  "type": "record",
  "name": "PojoCollection",
  "fields": [
    {
      "name": "collection",
      "type": {
        "type": "array",
        "items": {
          "name": "pojo",
          "type": "Pojo"
        }
      }
    }
  ]
}

My avro-maven-plugin is configured as follows:

<plugin>
    <groupId>org.apache.avro</groupId>
    <artifactId>avro-maven-plugin</artifactId>
    <version>1.8.2</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>schema</goal>
            </goals>
            <configuration>
                <imports>
                    <import>${basedir}/src/main/avro/Pojo.avsc</import>
                </imports>
            </configuration>
        </execution>
    </executions>
</plugin>

This causes the following exception:

Caused by: org.apache.avro.SchemaParseException: Type not supported: Pojo
    at org.apache.avro.Schema.parse(Schema.java:1319)
    at org.apache.avro.Schema.parse(Schema.java:1306)
    at org.apache.avro.Schema.parse(Schema.java:1269)
    at org.apache.avro.Schema$Parser.parse(Schema.java:1032)
    at org.apache.avro.Schema$Parser.parse(Schema.java:997)
    at org.apache.avro.mojo.SchemaMojo.doCompile(SchemaMojo.java:73)
    at org.apache.avro.mojo.AbstractAvroMojo.compileFiles(AbstractAvroMojo.java:223)
    at org.apache.avro.mojo.AbstractAvroMojo.execute(AbstractAvroMojo.java:172)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    ... 21 more

Is this an avro maven plugin bug? Or is it a problem with my avsc files?


Solution

  • it is an issue on your array definition. It should looks like

    {
      "namespace": "io.fama.pubsub.schema",
      "type": "record",
      "name": "PojoCollection",
      "fields": [
        {
          "name": "pojosCollection",
          "type": {
            "type": "array",
            "items": "Pojo"
          }
        }
      ]
    }
    

    The type of the array has to be define inside the items attribute.