Avro Maven 插件:不支持类型
Avro Maven Plugin: Type not supported
我有一个文件 Pojo.avsc
,其中包含以下声明:
{
"namespace": "io.fama.pubsub.schema",
"type": "record",
"name": "Pojo",
"fields": [
{
"name": "field",
"type": "string"
}
]
}
我有一个文件 PojoCollection.avsc
,其中仅包含一组 Pojo 对象。
{
"namespace": "io.fama.pubsub.schema",
"type": "record",
"name": "PojoCollection",
"fields": [
{
"name": "collection",
"type": {
"type": "array",
"items": {
"name": "pojo",
"type": "Pojo"
}
}
}
]
}
我的avro-maven-plugin配置如下:
<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>
这会导致以下异常:
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
这是 avro maven 插件错误吗?还是我的 avsc 文件有问题?
你的数组定义有问题。它应该看起来像
{
"namespace": "io.fama.pubsub.schema",
"type": "record",
"name": "PojoCollection",
"fields": [
{
"name": "pojosCollection",
"type": {
"type": "array",
"items": "Pojo"
}
}
]
}
数组的类型必须在 items
属性中定义。
我有一个文件 Pojo.avsc
,其中包含以下声明:
{
"namespace": "io.fama.pubsub.schema",
"type": "record",
"name": "Pojo",
"fields": [
{
"name": "field",
"type": "string"
}
]
}
我有一个文件 PojoCollection.avsc
,其中仅包含一组 Pojo 对象。
{
"namespace": "io.fama.pubsub.schema",
"type": "record",
"name": "PojoCollection",
"fields": [
{
"name": "collection",
"type": {
"type": "array",
"items": {
"name": "pojo",
"type": "Pojo"
}
}
}
]
}
我的avro-maven-plugin配置如下:
<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>
这会导致以下异常:
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
这是 avro maven 插件错误吗?还是我的 avsc 文件有问题?
你的数组定义有问题。它应该看起来像
{
"namespace": "io.fama.pubsub.schema",
"type": "record",
"name": "PojoCollection",
"fields": [
{
"name": "pojosCollection",
"type": {
"type": "array",
"items": "Pojo"
}
}
]
}
数组的类型必须在 items
属性中定义。