我目前正在使用AvroDataContractResolver将POCO从C#序列化到架构注册表中。我正在尝试进化模型以包含一个额外的字段,这是一个枚举。目前的模型如下所示。
[DataContract]
public class Person
{
[DataMember]
public string Name { get; set; }
[DataMember]
public int Age { get; set; }
}
其架构
{
"type": "record",
"name": "Person",
"namespace": "Core.Poco",
"fields": [
{
"name": "Name",
"type": [
"null",
"string"
]
},
{
"name": "Age",
"type": "int"
}
]
}
当我将enum Gender添加到人员POCO时,我需要为枚举添加默认值以使模式向后兼容。我正在查看https://github.com/welly87/Microsoft-Avro-Core处的代码,我没有看到任何方法为avro架构指定默认值。有没有办法指定一个默认值,或者有什么我缺少的东西?
答案 0 :(得分:0)
平均规格https://avro.apache.org/docs/1.8.2/spec.html使用默认关键字。假设Microsoft遵循规范。否则,请从https://www.nuget.org/packages/blachniet.Avro/下载nuget软件包,该软件包是dotnet core兼容的分支https://github.com/blachniet/avro 例如
{
"type": "record",
"name": "Person",
"namespace": "Core.Poco",
"fields": [
{
"name": "Name",
"type": [
"null",
"string"
]
},
{
"name": "Age",
"type": "int"
},
"name": "Gender",
"type": "int",
"default" : null,
]
}