question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nullable fields from schema are not reflected in generated C#

See original GitHub issue

Hello

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:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ievgenii-shepeliukcommented, Jan 19, 2022

Yes, worked. Thanks for your help !

0reactions
dstelljescommented, Feb 11, 2022

Full nullable reference type support is released with 8.0.0-pre.1.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found