-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fix test failures and proper fix this time #18
Changes from 1 commit
9cf6c41
1283ff6
3bd6b1c
f1ca39e
28b67b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -655,12 +655,6 @@ internal void InitializeForReflectionSerializer() | |
private JsonTypeInfo? GetTypeInfoInternal(Type type) | ||
{ | ||
IJsonTypeInfoResolver? resolver = _effectiveJsonTypeInfoResolver ?? _typeInfoResolver; | ||
|
||
if (resolver == null) | ||
{ | ||
ThrowHelper.ThrowInvalidOperationException_JsonTypeInfoUsedButTypeInfoResolverNotSet(); | ||
} | ||
|
||
JsonTypeInfo? info = resolver?.GetTypeInfo(type, this); | ||
|
||
if (info != null) | ||
|
@@ -728,6 +722,15 @@ internal void VerifyMutable() | |
} | ||
} | ||
|
||
internal void VerifyTypeInfoResolverIsSet() | ||
{ | ||
IJsonTypeInfoResolver? resolver = _effectiveJsonTypeInfoResolver ?? _typeInfoResolver; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, I think we should instead simply check if the options instance is mutable. What should happen if for example we have: var options = new JsonSerializerOptions();
var resolver = new DefaultJsonTypeInfoResolver();
JsonTypeInfo jti = resolver.GetTypeInfo(typeof(MyEnum), options);
options.Resolver = resolver;
options.Converter.Add(new JsonStringEnumConverter());
// jti now has inconsistent configuration relative to its encapsulated options instance There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And the more I think about it, I think we should make it impossible for JsonTypeInfo to encapsulate mutable options. In other words, JsonTypeInfo.CreateJsonTypeInfo(typeof(int), new JsonSerializerOptions()); // InvalidOperationException There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if we make that check there, we remove the need to do it in the (hot path) source gen serialization methods. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the place where we've originally hit this had locked options |
||
if (resolver == null) | ||
{ | ||
ThrowHelper.ThrowInvalidOperationException_JsonTypeInfoUsedButTypeInfoResolverNotSet(); | ||
} | ||
} | ||
|
||
private sealed class ConverterList : ConfigurationList<JsonConverter> | ||
{ | ||
private readonly JsonSerializerOptions _options; | ||
|
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.
Hmm, could the verification logic live inside
EnsureConfigured
? Or could this break other places where configuration is happening?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 unsure this is safe, I think yes but currently this check is not matching all callsites