我正在尝试使用Microsoft.Hadoop.Avro
库将通用记录(表示为JSON字符串)序列化为avro对象。
我一直在关注Generic Records HERE的教程。但是,我尝试序列化的记录比Microsoft(Location)提供的示例代码更复杂,JSON中包含嵌套属性。
以下是我想在Avro中序列化的记录示例:
{
"deviceId": "UnitTestDevice01",
"serializationFormat": "avro",
"messageType": "state",
"messageVersion": "avrov2.0",
"arrayProp": [
{
"itemProp1": "arrayValue1",
"itemProp2": "arrayValue2"
},
{
"itemProp1": "arrayValue3",
"itemProp2": "arrayValue4"
}
]
}
有关信息,这里是我可以提取的Avro架构:
{
"type": "record",
"namespace": "xxx.avro",
"name": "MachineModel",
"fields": [{
"name": "deviceId",
"type": ["string", "null"]
}, {
"name": "serializationFormat",
"type": ["string", "null"]
}, {
"name": "messageType",
"type": ["string", "null"]
}, {
"name": "messageVersion",
"type": ["string", "null"]
}, {
"name": "array",
"type": {
"type": "array",
"items": {
"type": "record",
"name": "array_record",
"fields": [{
"name": "arrayProp1",
"type": ["string", "null"]
}, {
"name": "arrayProp2",
"type": ["string", "null"]
}]
}
}
}]
}
我已设法为此对象提取正确的架构,但我无法正确获取架构并创建正确的Avro记录。
有人可以提供一些关于如何使用AvroSerializer
或AvroContainer
类来使用此json有效负载和此avro架构生成有效avro对象的指针吗?来自Microsoft的样本很容易处理复杂的对象,我也无法在线找到相关的样本。