我正在使用以下工具
<dependency>
<groupId>tech.allegro.schema.json2avro</groupId>
<artifactId>converter</artifactId>
<version>0.2.7</version>
</dependency>
将json转换为avro,但出现异常
Caused by: org.apache.avro.SchemaParseException: "enum" is not a defined name. The type of the "enumValue" field must be a defined name or a {"type": ...} expression.
at org.apache.avro.Schema.parse(Schema.java:1265)
at org.apache.avro.Schema$Parser.parse(Schema.java:1032)
at org.apache.avro.Schema$Parser.parse(Schema.java:997)
... removed by me, our code ...
用于avro模式:
{
"namespace": "test",
"type": "record",
"name": "test",
"fields": [
{
"name": "enumValue",
"type": "enum",
"symbols": [
"val_a",
"val_b"
]
}
]
}
和json:
{
"enumValue": "val_a"
}
依赖树显示avro 1.8.2
[INFO] +- org.apache.kafka:kafka-clients:jar:2.0.0:compile
[INFO] | +- org.lz4:lz4-java:jar:1.4.1:compile
[INFO] | +- org.xerial.snappy:snappy-java:jar:1.1.7.1:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- org.apache.avro:avro:jar:1.8.2:compile
[INFO] | +- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
[INFO] | +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] | | \- (org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile - omitted for duplicate)
[INFO] | +- com.thoughtworks.paranamer:paranamer:jar:2.7:compile
[INFO] | +- (org.xerial.snappy:snappy-java:jar:1.1.1.3:compile - omitted for conflict with 1.1.7.1)
[INFO] | +- org.apache.commons:commons-compress:jar:1.8.1:compile
[INFO] | +- org.tukaani:xz:jar:1.5:compile
[INFO] | \- (org.slf4j:slf4j-api:jar:1.7.7:compile - omitted for conflict with 1.7.25)
[INFO] +- tech.allegro.schema.json2avro:converter:jar:0.2.7:compile
[INFO] | \- (org.apache.avro:avro:jar:1.8.2:compile - omitted for duplicate)
[INFO] +- commons-io:commons-io:jar:2.6:compile
[INFO] +- info.picocli:picocli:jar:3.7.0:compile
[INFO] \- org.slf4j:slf4j-nop:jar:1.7.25:compile
[INFO] \- (org.slf4j:slf4j-api:jar:1.7.25:compile - omitted for duplicate)
而枚举的定义似乎与avro主页上的定义完全相同:
For example, playing card suits might be defined with:
{ "type": "enum",
"name": "Suit",
"symbols" : ["SPADES", "HEARTS", "DIAMONDS", "CLUBS"]
}
那么这里有什么问题呢?定义似乎没问题(是吗?),似乎使用了最新的avro,并且应该支持枚举。那么这是怎么了?
答案 0 :(得分:0)
我错了,正确的定义如下:
{
"namespace": "test",
"type": "record",
"name": "test",
"fields": [
{
"name": "enumValue",
"type": {
"name": "EnumType",
"type": "enum",
"symbols": [
"val_a",
"val_b"
]
}
}
]
}