Skip to content
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

Allow to disable behavior introduced by fix #100 in 1.8.0 - Stop StopLookupOnMatch #128

Closed
mulder999 opened this issue Mar 2, 2021 · 2 comments
Milestone

Comments

@mulder999
Copy link

mulder999 commented Mar 2, 2021

Before the fix #100, we could use the order to attempt best resolution.

The following json {"CommonProp": null, "Optional": null, "Other": null} raises "Ambiguous type resolution" while we would expect ClassC with former algo (or eventually ClassB if fallback could be used for ambiguous cases / but we really prefer former algo to deal with complex class trees).

        [JsonConverter(typeof(JsonSubtypes))]
        [JsonSubtypes.KnownSubTypeWithProperty(typeof(ClassC), nameof(ClassC.Other))]
        [JsonSubtypes.KnownSubTypeWithProperty(typeof(ClassB), nameof(ClassB.Optional))]
        [JsonSubtypes.FallBackSubType(typeof(ClassB))]
        public class ClassA
        {
            public string CommonProp { get; set; }
        }

        public class ClassB : ClassA
        {
            public bool? Optional { get; set; }
        }

        public class ClassC : ClassB
        {
            public string Other { get; set; }
        }
@manuc66 manuc66 added this to the 1.9.0 milestone Mar 2, 2021
@manuc66
Copy link
Owner

manuc66 commented Mar 17, 2021

@mulder999

Could this match your expectations ?

        [JsonConverter(typeof(JsonSubtypes))]
        [JsonSubtypes.KnownSubTypeWithProperty(typeof(ClassC), nameof(ClassC.Other), stopLookupOnMath: true)]
        [JsonSubtypes.KnownSubTypeWithProperty(typeof(ClassB), nameof(ClassB.Optional))]
        [JsonSubtypes.FallBackSubType(typeof(ClassB))]
        public class ClassA
        {
            public string CommonProp { get; set; }
        }
``

@mulder999
Copy link
Author

@manuc66 Thanks for coming back.

I guess there is a minor typo stopLookupOnMatch beside that, I believe this would do, assuming we can add it on several attributes.

@manuc66 manuc66 modified the milestones: 1.9.0, 1.10 Oct 22, 2021
@manuc66 manuc66 modified the milestones: 1.10, 2.0 Sep 10, 2022
@manuc66 manuc66 changed the title Allow to disable behavior introduced by fix #100 in 1.8.0 Allow to disable behavior introduced by fix #100 in 1.8.0 - Multiple type discriminators in JSON silently passes Sep 10, 2022
@manuc66 manuc66 changed the title Allow to disable behavior introduced by fix #100 in 1.8.0 - Multiple type discriminators in JSON silently passes Allow to disable behavior introduced by fix #100 in 1.8.0 - Stop StopLookupOnMatch Sep 10, 2022
manuc66 added a commit that referenced this issue Sep 10, 2022
manuc66 added a commit that referenced this issue Sep 10, 2022
@manuc66 manuc66 closed this as completed Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants