Nullable fields from schema are not reflected in generated C#
See original GitHub issueHello
I’m using dotnet avro generate
to create C# class from Avro schema.
My schema looks like
{
"name": "Models.MyClass",
"type": "record",
"fields": [
{"name": "BoolField", "type": ["null", "boolean"]},
{"name": "StringField", "type": ["null", "string"]},
{
"name": "RecordField",
"type": ["null", {
"name": "Models.Credentials",
"type": "record",
"fields": [
{"name": "Password", "type": "string"},
{"name": "Username", "type": "string"}
]
}]
}, {
"name": "EnumField",
"type": ["null", {
"name": "Models.AccountStatus",
"type": "enum",
"symbols": ["New", "Active"]
}]
}
]
}
I expect that properties BoolField
, StringField
, RecordField
, EnumField
will be nullable in generated class. But they are not.
The resulting C# class looks like
namespace Models
{
public enum AccountStatus
{
New,
Active
}
public class Credentials
{
public string Password { get; set; }
public string Username { get; set; }
}
public class MyClass
{
public bool? BoolField { get; set; }
public string StringField { get; set; }
public Credentials RecordField { get; set; }
public AccountStatus EnumField { get; set; }
}
}
Am I missing smth or this is a bug in code generation ?
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Why are all fields null when querying with schema?
Without a schema, all data are strings so anything matches fine. You have to specify a proper format using timestampFormat option to parse...
Read more >Making the difference between null and not loaded fields
1 Answer 1 ... If you set a field to null in your working code, it will display in the map from getPopulatedFieldsAsMap...
Read more >[C#] Not nullable field can have null values · Issue #30567
When the record batch schema field's parameter of nullable is set to false, it supposes to make the field not null, however, ...
Read more >Support nullable & optional/required · Issue #542 · graphql ...
In GraphQL we can mark a field that it is nullable or not by "!". But how to also mark that a field...
Read more >Dealing with null in Spark
Native Spark code handles null gracefully. Let's create a DataFrame with numbers so we have some data to play with. val schema =...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, worked. Thanks for your help !
Full nullable reference type support is released with 8.0.0-pre.1.