Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

JsonSerializerOptions API update and ignore property features #36776

Merged
merged 2 commits into from
Apr 13, 2019

Conversation

steveharter
Copy link
Member

Apply the approved API changes. Includes some new functionality including an [Ignore] that can be applied to properties and ability to ignore just read-only properties on serialization via options.IgnoreReadOnlyProperties.

Fixes https://github.com/dotnet/corefx/issues/34372

@steveharter steveharter added this to the 3.0 milestone Apr 10, 2019
@steveharter steveharter self-assigned this Apr 10, 2019
src/System.Text.Json/ref/System.Text.Json.cs Show resolved Hide resolved

internal abstract object GetValueAsObject(object obj, JsonSerializerOptions options);
bool hasIgnoreAttribute = (GetAttribute<JsonIgnoreAttribute>() != null);
Copy link
Member

Choose a reason for hiding this comment

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

nit: remove unnecessary brackets.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have a slight preference and think the brackets make it more obvious that this is a bool... Willing to change it however if I'm the only one :)

options = new JsonSerializerOptions();
options.WriteIndented = true;
json = JsonSerializer.ToString(obj, options);
Assert.Contains("\r", json);
Copy link
Member

Choose a reason for hiding this comment

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

I am surprised this is passing on unix.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes... I assume the writer is using Environment.NewLine?

@steveharter steveharter merged commit b06250e into dotnet:master Apr 13, 2019
@steveharter steveharter deleted the JsonOptions branch April 13, 2019 22:32
@@ -162,7 +162,7 @@ public JsonCommentHandling ReadCommentHandling
}

/// <summary>
/// Defines whether the <see cref="Utf8JsonWriter"/> should pretty print the JSON which includes:
/// Defines whether JSON should pretty print which includes:
Copy link
Member

Choose a reason for hiding this comment

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

JSON should be pretty printed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Object (de)serialization support with Utf8JsonReader\Writer - entry point and options
5 participants