I'm using following tool
<dependency>
<groupId>tech.allegro.schema.json2avro</groupId>
<artifactId>converter</artifactId>
<version>0.2.7</version>
</dependency>
to convert json to avro, but I'm getting exception
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 ...
for avro schema:
{
"namespace": "test",
"type": "record",
"name": "test",
"fields": [
{
"name": "enumValue",
"type": "enum",
"symbols": [
"val_a",
"val_b"
]
}
]
}
and json:
{
"enumValue": "val_a"
}
dependency tree shows 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)
while enum definition seems to be quite the same as the one from avro home page:
For example, playing card suits might be defined with:
{ "type": "enum",
"name": "Suit",
"symbols" : ["SPADES", "HEARTS", "DIAMONDS", "CLUBS"]
}
So what can be wrong here? Definitions seems to be OK (is it?), latest avro seems to be used and that one should support enums. So what is wrong here?
I was wrong, correct definition looks like:
{
"namespace": "test",
"type": "record",
"name": "test",
"fields": [
{
"name": "enumValue",
"type": {
"name": "EnumType",
"type": "enum",
"symbols": [
"val_a",
"val_b"
]
}
}
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With