Skip to content

Fix JsonIgnoreCondition.WhenWritingNull doc#128127

Open
lilinus wants to merge 1 commit into
dotnet:mainfrom
lilinus:JsonIgnoreCondition.WhenWritingNull-doc
Open

Fix JsonIgnoreCondition.WhenWritingNull doc#128127
lilinus wants to merge 1 commit into
dotnet:mainfrom
lilinus:JsonIgnoreCondition.WhenWritingNull-doc

Conversation

@lilinus
Copy link
Copy Markdown
Contributor

@lilinus lilinus commented May 13, 2026

Doc only

It acutally applies to nullable value types too

using System;
using System.Text.Json;
using System.Text.Json.Serialization;

Forecast forecast = new()
{
    Date = null,
};
JsonSerializerOptions options = new()
{
    DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
string forecastJson = JsonSerializer.Serialize<Forecast>(forecast, options);
Console.WriteLine(forecastJson); // Prints "{}"

public class Forecast
{
    public DateTime? Date { get; set; }
};

Should I manually make PR to https://github.com/dotnet/docs ?

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label May 13, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-json
See info in area-owners.md if you want to be subscribed.

/// <summary>
/// If the value is <see langword="null"/>, the property is ignored during serialization.
/// This is applied only to reference-type properties and fields.
/// This is applied only to reference and nullable value-type properties and fields.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep simple?

Suggested change
/// This is applied only to reference and nullable value-type properties and fields.
/// This is applied only to nullable type properties and fields.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, unless it can be misinterpreted as not applied to non-nullable reference types in context. WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Text.Json community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants