获取非法的初始字符:在模式解析中

nvbavucw  于 2021-06-07  发布在  Kafka
关注(0)|答案(1)|浏览(484)

我正在使用avro1.8.1并尝试解析以下模式2。你能帮忙吗?

val schema: Schema = new Schema.Parser().parse(StrSchema) 

I am getting following exception.
Exception in thread "main" org.apache.avro.SchemaParseException: Illegal initial character: {"type":"record","name":"WS_MESSAGES","fields":[{"name":"message_id","type":"string"},{"name":"action","type":"string"},{"name":"status","type":"string"},{"name":"request","type":"string"},{"name":"response","type":"string"}]} 

at org.apache.avro.Schema.validateName(Schema.java:1079) 
        at org.apache.avro.Schema.access$200(Schema.java:79) 
        at org.apache.avro.Schema$Name.<init>(Schema.java:436) 
        at org.apache.avro.Schema$Names.get(Schema.java:1043) 
        at org.apache.avro.Schema.parse(Schema.java:1160) 
        at org.apache.avro.Schema$Parser.parse(Schema.java:965) 
        at org.apache.avro.Schema$Parser.parse(Schema.java:953) 
        at main.scala.SampleStreaming$.main(SampleStreaming.scala:42) 
        at main.scala.SampleStreaming.main(SampleStreaming.scala)

模式2:

"{\"type\":\"record\",\"name\":\"WS_MESSAGES\",\"fields\":[{\"name\":\"message_id\",\"type\":\"string\"},{\"name\":\"action\",\"type\":\"string\"},{\"name\":\"status\",\"type\":\"string\"},{\"name\":\"request\",\"type\":\"string\"},{\"name\":\"response\",\"type\":\"string\"}]}"

我最初试图解析下面的模式\u1,但出现了不同的错误,然后操纵字符串以生成上面的模式\u2。

Exception in thread "main" org.apache.avro.SchemaParseException: No type: {"schema":"{\"type\":\"record\",\"name\":\"WS_MESSAGES\",\"fields\":[{\"name\":\"message_id\",\"type\":\"string\"},{\"name\":\"action\",\"type\":\"string\"},{\"name\":\"status\",\"type\":\"string\"},{\"name\":\"request\",\"type\":\"string\"},{\"name\":\"response\",\"type\":\"string\"}],\"connect.name\":\"WS_MESSAGES\"}"} 
        at org.apache.avro.Schema.getRequiredText(Schema.java:1305) 
        at org.apache.avro.Schema.parse(Schema.java:1166) 

Schema_1: 

    {"schema":"{\"type\":\"record\",\"name\":\"WS_MESSAGES\",\"fields\":[{\"name\":\"message_id\",\"type\":\"string\"},{\"name\":\"action\",\"type\":\"string\"},{\"name\":\"status\",\"type\":\"string\"},{\"name\":\"request\",\"type\":\"string\"},{\"name\":\"response\",\"type\":\"string\"}],\"connect.name\":\"WS_MESSAGES\"}"} 

Thanks, 
Amritendu
sulc1iza

sulc1iza1#

我想,问题是,您在名称字段(connect.name)中使用了点(.)。这是不允许的。看一下阿芙罗的名字

相关问题