Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Initial Json serialization functionality - #35609

Merged
steveharter merged 11 commits into
dotnet:masterfrom
steveharter:JsonSerializer
Mar 2, 2019
Merged

steveharter merged 11 commits into
dotnet:masterfrom
steveharter:JsonSerializer

Conversation

@steveharter

@steveharter steveharter commented Feb 27, 2019 •

Copy link
Copy Markdown
Contributor

This adds basic Json serialization functionality per https://github.com/dotnet/corefx/issues/34372

Notes:

  • Only the APIs which have been reviewed are present which includes the main entry points in JsonSerializer and the corresponding options class JsonSerializerOptions. This does not include the extensibility model that that existed in the prototype.
  • The extensibility model is currently under design and review.
  • Api documentation will be added soon to the reviewed APIs.

cc @joshfree @terrajobst @davidfowl

@steveharter steveharter added * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) area-System.Text.Json labels Feb 27, 2019
@steveharter steveharter self-assigned this Feb 27, 2019

namespace System.Text.Json.Serialization
{
// Note: this is currently an internal class that will be replaced with a shared version.

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.

My understanding from the API review is that the shared version will actually be something like a ReadOnlySequenceWriter. Will that work for the serializer's needs? If so, can it be adapted to that design now?

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.

@ahsonkhan what is the status of having a public implementation of IBufferWriter?

@steveharter steveharter removed the * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) label Feb 27, 2019
@steveharter
steveharter force-pushed the JsonSerializer branch 2 times, most recently from f0940cf to a42abf4 Compare March 1, 2019 19:27
Type propertyType = PropertyType;
if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
propertyType = Nullable.GetUnderlyingType(propertyType);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps cache the non-nullable property type so it's not computed on each property being read?

@steveharter

Copy link
Copy Markdown
Contributor Author

I've addressed the active concerns and will commit this soon pending no new actionable feedback. Thanks.

@ahsonkhan ahsonkhan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Otherwise, LGTM.

// We have less than half the buffer available, double the buffer size.
bufferSize = (bufferSize < HalfMaxValue) ? bufferSize * 2 : int.MaxValue;

byte[] dest = ArrayPool<byte>.Shared.Rent(bufferSize);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Renting int.MaxValue would throw OOM. Should we cap it to something smaller (either 2GB, or maybe int.MaxValue - 56)?

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.

Do we have a policy on this elsewhere? It seems like a common scenario.

Assert.Null(objCopy.GetMyString());
}

// Todo: add tests with missing object property and missing collection property.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you file an issue to improve test coverage here. Also to track your earlier comment:

Branch coverage is 80%-100% depending on file, but somewhat hampered because some tests are disabled because some of the APIs are not yet public (they were made internal). I do need more negative tests.

@steveharter
steveharter merged commit 20657b5 into dotnet:master Mar 2, 2019
@steveharter
steveharter deleted the JsonSerializer branch March 2, 2019 19:20
@davidfowl

Copy link
Copy Markdown
Member

W00p!

}
namespace System.Text.Json.Serialization
{
public static partial class JsonSerializer

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.

Oh wait this PR removed the PipeReader and PipeWriter overloads 😢

@TylerBrinkley

Copy link
Copy Markdown

FYI, I've removed the need for Nullable converters and have added support for generic enum converters in #35754.

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.

6 participants