-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nullable fields from schema are not reflected in generated C# #169
Comments
At the moment, code generation only supports nullable value types (note the That said, enums are value types and thus should be supported currently; #171 fixes that bug and will be included in the next 7.2.x. |
Looking forward new release, thanks for fixing it. |
@dstelljes is it possible to somehow hack it on serialization level, so even if fields is not nullable in C# class - when value of reference type is null - it will be serialized as |
Yes, that’s how Chr.Avro currently behaves—the library is oblivious to C# 8+ nullable reference types. |
Can you provide an example ? I have an exception when serializing messages. Although I have more complicated setup - i am wrapping Chr.Avro serializer to use it together with https://github.com/Farfetch/kafka-flow I am creating an instance
and then invoke |
Sure, say I’m using your schema: {
"name": "Models.MyClass",
"type": "record",
"fields": [
{
"name": "RecordField",
"type": ["null", {
"name": "Models.Credentials",
"type": "record",
"fields": [
{"name": "Password", "type": "string"},
{"name": "Username", "type": "string"}
]
}]
}
]
} and mapping it to these classes: #nullable disable // turn off nullable reference types to match Chr.Avro
namespace Models
{
public class Credentials
{
public string Password { get; set; }
public string Username { get; set; }
}
public class MyClass
{
public Credentials RecordField { get; set; }
}
} the serializer would allow me to do this: var context = new SerializationContext(MessageComponentType.Value, "example-topic");
// this should work because `RecordField` is `["null", ...]`
await _serializer.SerializeAsync(new MyClass { RecordField = null }, context); but not this: var context = new SerializationContext(MessageComponentType.Value, "example-topic");
// this would not work because `Password` is not `["null", ...]`
await _serializer.SerializeAsync(new MyClass { RecordField = new Credentials { Username = "user", Password = null } }, context); |
Yes, worked. Thanks for your help ! |
Full nullable reference type support is released with 8.0.0-pre.1. |
Hello
I'm using
dotnet avro generate
to create C# class from Avro schema.My schema looks like
I expect that properties
BoolField
,StringField
,RecordField
,EnumField
will be nullable in generated class. But they are not.The resulting C# class looks like
Am I missing smth or this is a bug in code generation ?
The text was updated successfully, but these errors were encountered: