是否可以为 Dictionary 对象创建 Avro 模式
Is it possible to create Avro schema for Dictionary object
尝试在 .net 中为 kafka 消息实现 avro 序列化和反序列化。消息模型如下
public class SampleMessage
{
public string Hash{ get; set; }
public string FileName { get; set; }
public string Data { get; set; }
public Dictionary<string, string> Content { get; set; }
public string LineDetails { get; set; }
}
那么,是否可以在 c# 中为 Dictionary 创建 Avro 架构?
是的。为此,您应该使用复杂类型“地图”(https://avro.apache.org/docs/current/spec.html#Maps
Maps use the type name "map" and support one attribute:
values: the schema of the map's values.
Map keys are assumed to be strings.
举个例子,你的 .avsc 看起来像这样:
{
"type": "record",
"name": "SampleMessage",
"namespace": "samplemessage",
"fields": [
{
"name": "hash",
"type": "string"
},
{
"name": "fileName",
"type": "string"
},
{
"name": "data",
"type": "string"
},
{
"name": "content",
"type": {
"type": "map",
"values": "string"
}
},
{
"name": "lineDetails",
"type": "string"
}
]
}
尝试在 .net 中为 kafka 消息实现 avro 序列化和反序列化。消息模型如下
public class SampleMessage
{
public string Hash{ get; set; }
public string FileName { get; set; }
public string Data { get; set; }
public Dictionary<string, string> Content { get; set; }
public string LineDetails { get; set; }
}
那么,是否可以在 c# 中为 Dictionary 创建 Avro 架构?
是的。为此,您应该使用复杂类型“地图”(https://avro.apache.org/docs/current/spec.html#Maps
Maps use the type name "map" and support one attribute:
values: the schema of the map's values.
Map keys are assumed to be strings.
举个例子,你的 .avsc 看起来像这样:
{
"type": "record",
"name": "SampleMessage",
"namespace": "samplemessage",
"fields": [
{
"name": "hash",
"type": "string"
},
{
"name": "fileName",
"type": "string"
},
{
"name": "data",
"type": "string"
},
{
"name": "content",
"type": {
"type": "map",
"values": "string"
}
},
{
"name": "lineDetails",
"type": "string"
}
]
}