-
Notifications
You must be signed in to change notification settings - Fork 8
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
Custom Name resolver #31
base: master
Are you sure you want to change the base?
Conversation
…set; } = type => type.Name;` to JsonDiscriminatorSettings to allow custom Name Discriminator Resolver - Added JsonKnownTypesSettingsManager<T> To allow type specific config to be injected
PR resolves #30 |
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.
Sorry for long response
Can you pls create test for the case, also update language version in project to latest
Also have found issue (not yours) with mapper if user specified DiscriminatorAttribute
it will use new JsonDiscriminatorSettings
to compare but need to use it from JsonKnownTypesSettingsManager
.
I think it's all connected so what can be done here
So i think need to create some comparator to resolve that perfect way
but overall looks ok!
var discriminatorSettings = discriminatorAttribute == null | ||
? DefaultDiscriminatorSettings | ||
var discriminatorSettings = discriminatorAttribute == null | ||
? JsonKnownTypesSettingsManager<T>.DefaultDiscriminatorSettings |
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.
This is never null
so it always use settings from generic manager
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.
This will be null unless you explicitly set generic settings. For example: JsonKnownTypesSettingsManager<ClassWithDuplicateChild>.DefaultDiscriminatorSettings.NameDiscriminatorResolver = type => type.FullName;
So, first it looks for the attribute, if that is null, it will look for a specific setting for the generic type (<ClassWithDuplicateChild>
in the example), if that is also null it will fall back to the default settings.
At least thats how it worked in my unittest
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.
Can you pls create test for the case,
I did add a test for the case, it's the last file in the PR:
https://github.com/dmitry-bym/JsonKnownTypes/blob/4e99657912ef8ef8c17ec7bd8573a9b64ab2a390/tests/JsonKnownTypes.UnitTests/WithNameDiscriminatorResolverTests.cs
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.
@RonSijm nope its not null cause there is default value there
public static class JsonKnownTypesSettingsManager<T>
{
/// <summary>
/// Type specific default settings for discriminator
/// </summary>
// ReSharper disable once StaticMemberInGenericType - Justification: Intentional property should exist on a per-type base
public static JsonDiscriminatorSettings DefaultDiscriminatorSettings { get; } = new();
}
public Func<Type, string> NameDiscriminatorResolver { get; set; } = type => type.Name;
to JsonDiscriminatorSettings to allow custom Name Discriminator Resolver