-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new APIs for code gen #50
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks exciting
...xt/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Small.cs
Outdated
Show resolved
Hide resolved
...tem.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectCodeGenConverter.cs
Outdated
Show resolved
Hide resolved
|
||
namespace System.Text.Json.Serialization.Converters | ||
{ | ||
/// <summary> | ||
/// Default base class implementation of <cref>JsonObjectConverter{T}</cref>. | ||
/// </summary> | ||
internal class ObjectDefaultConverter<T> : JsonObjectConverter<T> where T : notnull | ||
internal class ObjectDefaultConverter<T> : JsonObjectConverter<T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the change to notnull
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why this was originally added; affects new usage of generics added elsewhere. T
can be null...
@@ -68,6 +70,8 @@ internal override sealed JsonParameterInfo CreateJsonParameterInfo() | |||
/// </summary> | |||
internal bool CanBeNull { get; } | |||
|
|||
internal readonly EqualityComparer<T> _defaultComparer = EqualityComparer<T>.Default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes in JsonPropertyInfo WriteValue
and Write
. I believe you refactored this earlier in master; not sure if this branch is up-to-date with master to have that change yet.
{ | ||
_isInitialized = true; | ||
|
||
//todo: should we not add? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the benefit of adding given all the generated TypeInfos have references to each other via their JsonPropertyInfo
s?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It allows direct usage of the type in the existing (De)Serialize methods without having to fall back to reflection\IL Emit, and also allows options.GetConverter(type)
to return the type without reflection\IL Emit.
} | ||
} | ||
|
||
// todo: add SerializeAsync method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a proof-of-concept, just the DeserializeAsync was added (to ensure callers can still use that, even though the generated (de)serialize methods won't get called. The SerializeAsync will be added next pass.
Test failure is not related: System.Net.Http.Functional.Tests |
* Add support for properties * PR feedback - Avoid creating PropertyMap rows for types without properties - Use GetAccessors to get property accessors * PR feedback - Don't forget to map tokens!
Per offline reviews, this is a first pass at adding new public APIs to support the code-gen effort.
Primarily this exposes the existing internal metadata classes (JsonPropertyInfo\JsonClassInfo) as public and also extends these existing classes by adding derived classes (for value-based, object-based and collection-based types) along with helper methods to initialize the metadata and (de)serialize.
There is still work remaining including:
ReadStack
,WriteStack
andJsonClassInfo
.JsonSerializerOptions
that will not initialize the built-in converters and prevent the Emit- and Reflection-basedMemberAccessor
strategies from being used.