Skip to content
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

Handling nullable reference types #4

Open
markjamesm opened this issue May 24, 2021 · 1 comment
Open

Handling nullable reference types #4

markjamesm opened this issue May 24, 2021 · 1 comment
Labels
question Further information is requested
Milestone

Comments

@markjamesm
Copy link
Owner

markjamesm commented May 24, 2021

As I'm currently unsure as to which JSON responses may or may not contain null values, I'm treating all DTO class properties as nullable, and Nullable reference types are enabled project-wide as specified in the BaseballSharp .csproj file.

Treating all DTO properties as nullable means that there is a significant amount of ? (nullable) annotation throughout the code base. So far, I've only ever experienced the pitching report notes endpoint return null for a certain date.

Some proposed alternatives to this style would be:

  • Skip marking the fields nullable. However, nullable reference type annotations are a feature for the code author; and even if you mark a reference field as non-nullable, this does not mean it is not null on the write.

  • Alternatively, we can just accept NullReferenceExceptions if some data is unusual.

  • If we want to avoid NullReferenceExceptions then we could validate all the deserialized DTOs to ensure that non-nullable fields do not actually contain null values.

I feel the cleanest option is likely option 3, to validate the DTOs after deserialization and throw when some mystery null values appear, only marking as nullable the "I expect this to sometimes be null" fields.

@markjamesm markjamesm added the question Further information is requested label May 24, 2021
@markjamesm
Copy link
Owner Author

This has been partially resolved by using property initializers. The next step is to implement error handling as per this issue:
#16

Once the error handling is finished I will close this issue.

@markjamesm markjamesm added this to the 1.0.0 milestone Jan 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant