© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
15 replies
Twilight Rose

❔ JSON serialization nullable warnings (best approach?)

Kind of have a "best approach" question for the following:
using System.Text.Json;

class FileVerification
{
    private readonly string quackenFilePath = @"C:\Users\maske\Documents\dev\CSharp\TelegramBots\quacken.json";

    private readonly JsonSerializerOptions _options = new()
    {
        PropertyNameCaseInsensitive = true
    };
    public List<QuackenJson> JsonReadWithSystemText()
    {
        using FileStream json = File.OpenRead(quackenFilePath);
        List<QuackenJson> token = JsonSerializer.Deserialize<List<QuackenJson>>(json, _options)!;
        return token;
    }
}
using System.Text.Json;

class FileVerification
{
    private readonly string quackenFilePath = @"C:\Users\maske\Documents\dev\CSharp\TelegramBots\quacken.json";

    private readonly JsonSerializerOptions _options = new()
    {
        PropertyNameCaseInsensitive = true
    };
    public List<QuackenJson> JsonReadWithSystemText()
    {
        using FileStream json = File.OpenRead(quackenFilePath);
        List<QuackenJson> token = JsonSerializer.Deserialize<List<QuackenJson>>(json, _options)!;
        return token;
    }
}

Would you make it nullable using
?
?
or
??
??
in the appropriate spots, or (in this particular case) since I know the value will never be null, would you do as I have and use
!
!
to suppress the warning?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Best practices regarding non-nullable property warnings?
C#CC# / help
2y ago
✅ Dealing/resolving nullable warnings
C#CC# / help
3y ago
✅ NodaTime JSON Serialization
C#CC# / help
2y ago
❔ JSON serialization fails
C#CC# / help
3y ago