<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/getting-rid-of-warnings-with-nullable-reference-types-and-json-object-models-in-c--75cf6i9be" -->

---
title: Getting rid of warnings with nullable reference types...
description: Covers five approaches to resolving nullable reference type compiler warnings when deserializing JSON into C# DTO/POCO classes: making properties nullable,...
canonical: https://daily.dev/posts/getting-rid-of-warnings-with-nullable-reference-types-and-json-object-models-in-c--75cf6i9be
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Getting rid of warnings with nullable reference types and JSON object models in C# | daily.dev
og:description: Covers five approaches to resolving nullable reference type compiler warnings when deserializing JSON into C# DTO/POCO classes: making properties nullable,...
og:url: https://daily.dev/posts/getting-rid-of-warnings-with-nullable-reference-types-and-json-object-models-in-c--75cf6i9be
og:image: https://api.daily.dev/og/posts/75Cf6i9bE.png
og:image:alt: Getting rid of warnings with nullable reference types and JSON object models in C#
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Getting rid of warnings with nullable reference types and JSON object models in C#

**[Maarten Balliauw](https://daily.dev/sources/maartenballiauw)** · 5 min read · 0 upvotes · 0 comments

## Summary

Covers five approaches to resolving nullable reference type compiler warnings when deserializing JSON into C# DTO/POCO classes: making properties nullable, using default! (discouraged), adding a primary constructor, setting default values via annotations, and using the C# 11 required modifier. The required property approach is presented as the author's preferred solution since it enforces initialization without feeding the compiler false nullability information, though it's only a compile-time guarantee, not a runtime one.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.maartenballiauw.be/posts/2023-01-12-getting-rid-of-warnings-with-nullable-reference-types-and-json-object-models-in-csharp>

## Questions this post answers

### How do I stop the compiler warning about non-nullable properties when deserializing JSON in C#?

Use the required modifier introduced in C# 11 on the property instead of making it nullable or assigning default!. This forces the compiler to expect the property to always be initialized, removing the nullable warning without lying to the compiler about potential null values, though the guarantee is enforced only at compile time, not at runtime.

_daily.dev surfaces practical C# patterns like this for developers wrestling with nullable warnings._

### Why shouldn't I use default! to fix nullable reference warnings in C#?

Using default! suppresses the compiler warning but silently sets the property to null if the JSON lacks that value, which can trigger unexpected NullReferenceException at runtime. This sabotages the null safety net that nullable reference types are meant to provide, since the compiler now wrongly assumes the property is always non-null.

_Developers tightening null safety in C# codebases can track patterns like this via daily.dev._

### Can Newtonsoft.Json call a constructor instead of setting properties directly when deserializing?

Yes, if a class defines a primary constructor that sets all non-nullable properties, Newtonsoft.Json's deserializer will detect and call that constructor rather than setting properties directly. This lets you throw an ArgumentNullException or assign a default value when a JSON field is missing, closely modeling the C# class after the expected JSON shape.

_daily.dev helps developers comparing JSON deserialization patterns in C# find approaches like this one._

## Similar posts on daily.dev

- [Taming the Billion Dollar Mistake: Maarten Balliauw's Guide to C\# Nullable Reference Types](https://daily.dev/posts/taming-the-billion-dollar-mistake-maarten-balliauw-s-guide-to-c-nullable-reference-types-dhuc5b5o7) · JetBrains · 5 upvotes · 0 comments
- [Model variable JSON field types with unions](https://daily.dev/posts/model-variable-json-field-types-with-unions-4ugh6mlue) · Damir's Corner · 6 upvotes · 0 comments
- [.NET 10: System.Text.Json Improvements – Anthony Giretti's .NET blog](https://daily.dev/posts/net-10-system-text-json-improvements-anthony-giretti-s-net-blog-ax0fgx0md) · We Are .NET · 18 upvotes · 0 comments
- [Why I Switched to Primary Constructors for DI in C\#](https://daily.dev/posts/why-i-switched-to-primary-constructors-for-di-in-c--ctodiijms) · Milan Jovanović · 53 upvotes · 4 comments

---

Tags: [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/getting-rid-of-warnings-with-nullable-reference-types-and-json-object-models-in-c--75cf6i9be)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Getting rid of warnings with nullable reference types and JSON object models in C#","url":"https://daily.dev/posts/getting-rid-of-warnings-with-nullable-reference-types-and-json-object-models-in-c--75cf6i9be","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/getting-rid-of-warnings-with-nullable-reference-types-and-json-object-models-in-c--75cf6i9be"},"datePublished":"2026-10-04T13:04:27.265Z","dateModified":"2026-10-04T13:05:57.556Z","description":"Covers five approaches to resolving nullable reference type compiler warnings when deserializing JSON into C# DTO/POCO classes: making properties nullable,...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/1cf1cb5cb454e4e085b882dddbc8a286?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/1cf1cb5cb454e4e085b882dddbc8a286?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Maarten Balliauw","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Maarten Balliauw","logo":"https://media.daily.dev/image/upload/s--rOTg3VYO--/f_auto,q_auto/v1791119043/logos/maartenballiauw?_a=BAMAMicg0","url":"https://daily.dev/sources/maartenballiauw"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/getting-rid-of-warnings-with-nullable-reference-types-and-json-object-models-in-c--75cf6i9be","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"c#","timeRequired":"PT5M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Maarten Balliauw","item":"https://daily.dev/sources/maartenballiauw"},{"@type":"ListItem","position":3,"name":"Getting rid of warnings with nullable reference types and JSON object models in C#"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/getting-rid-of-warnings-with-nullable-reference-types-and-json-object-models-in-c--75cf6i9be#faq","mainEntity":[{"@type":"Question","name":"How do I stop the compiler warning about non-nullable properties when deserializing JSON in C#?","acceptedAnswer":{"@type":"Answer","text":"Use the required modifier introduced in C# 11 on the property instead of making it nullable or assigning default!. This forces the compiler to expect the property to always be initialized, removing the nullable warning without lying to the compiler about potential null values, though the guarantee is enforced only at compile time, not at runtime. daily.dev surfaces practical C# patterns like this for developers wrestling with nullable warnings."}},{"@type":"Question","name":"Why shouldn't I use default! to fix nullable reference warnings in C#?","acceptedAnswer":{"@type":"Answer","text":"Using default! suppresses the compiler warning but silently sets the property to null if the JSON lacks that value, which can trigger unexpected NullReferenceException at runtime. This sabotages the null safety net that nullable reference types are meant to provide, since the compiler now wrongly assumes the property is always non-null. Developers tightening null safety in C# codebases can track patterns like this via daily.dev."}},{"@type":"Question","name":"Can Newtonsoft.Json call a constructor instead of setting properties directly when deserializing?","acceptedAnswer":{"@type":"Answer","text":"Yes, if a class defines a primary constructor that sets all non-nullable properties, Newtonsoft.Json's deserializer will detect and call that constructor rather than setting properties directly. This lets you throw an ArgumentNullException or assign a default value when a JSON field is missing, closely modeling the C# class after the expected JSON shape. daily.dev helps developers comparing JSON deserialization patterns in C# find approaches like this one."}}]}
```

