1

I currently having an issue with the Avro JsonDecoder. Avro is used in Version 1.8.2. The .avsc file is defined like:

{
"type": "record",
"namespace": "my.namespace",
"name": "recordName",
"fields": [
    {
        "name": "Code",
        "type": "string"
    },
    {
        "name": "CodeNumber",
        "type": "string",
        "default": ""
    }
  ]
}

When I now run my test cases I get an org.apache.avro.AvroTypeException: Expected string. Got END_OBJECT. The class throwing the error is JasonDecoder. For me it looks like the defaut value handling on my side might not be correct with using just "" as the default value. The error occurs only if the field is not available at all, but this, in my understanding, is the case when the default value should be used. If I set the value in the json as "CodeNumber": "" the decoder does not have any issues. Any hints or ideas?

4

2 回答 2

0

发现这个:

原来问题是java实现只是忽略了默认值。我添加了一个解决方法,它将捕获异常然后查找默认值。将在 1.9.0 版本中发布

来源:https ://github.com/sksamuel/avro4s/issues/106

如果可能,请尝试将您的 Avro 解码器升级到 1.9.0 版本。

于 2020-04-14T14:53:30.850 回答
-1

我建议使用null它,因为它在逻辑上更好:

{
    "name": "CodeNumber",
    "type": ["string", "null"],
    "default": null
}
于 2020-04-14T19:37:15.230 回答