【发布时间】:2021-08-26 16:57:18
【问题描述】:
我在我的 avro 架构中定义了一个字段,如下所示。
{
"name": "currency",
"type": ["null","string"],
"default": null
},
我收到一些不包含字段货币的 json 数据,它总是抛出这个错误。
Expected field name not found: currency
我使用以下代码将其转换为通用对象。
DecoderFactory decoderFactory = new DecoderFactory();
Decoder decoder = decoderFactory.jsonDecoder(schema, eventDto.toString());
DatumReader<GenericData.Record> reader =
new GenericDatumReader<>(schema);
GenericRecord genericRecord = reader.read(null, decoder);
大多数 stackoverflow 和 github 答案表明我在上面所做的应该使这些字段成为可选的并且应该可以正常工作。但这似乎对我不起作用。有没有办法解决这个问题。
【问题讨论】:
-
你在用什么库?
-
@SimranTea avro maven 依赖项。 1.10.2版