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

Add support for MissingMemberHandling #43

Closed
SigmundVik opened this issue Jun 15, 2020 · 7 comments
Closed

Add support for MissingMemberHandling #43

SigmundVik opened this issue Jun 15, 2020 · 7 comments

Comments

@SigmundVik
Copy link

SigmundVik commented Jun 15, 2020

It would be great if Dahomey.Json could support MissingMemberHandling. This would help us build a robust API that does not let user mistakes slip by unnoticed (for our ASP.NET Core application).

Support for this feature might get added to System.Text.Json, but it is unclear if or when that will happen - see the 5.0 and Future milestone indicators here.

@mcatanzariti
Copy link
Member

Please find an example here:
https://github.com/dahomey-technologies/Dahomey.Json/blob/master/src/Dahomey.Json.Tests/MissingMemberHandlingTests.cs

@SigmundVik
Copy link
Author

SigmundVik commented Jul 7, 2020

Thank you so much for adding support for this!

However, there are two things that are problematic:

  1. MissingMemberHandling.Error does not work for polymorphic types; an exception with message Missing member '<name of the discriminator property>' always gets thrown for such a type.
  2. The exception message is probably going to be confusing to an end user ("but the member is not missing, it is right there!"). I think a message like Unrecognized property name '<name of property>' would help the user to more quickly realize what is wrong.

@SigmundVik
Copy link
Author

@mcatanzariti, should we reopen this issue, or do you want me to file new issue(s)?

@mcatanzariti
Copy link
Member

Yes let's reopen it

@mcatanzariti mcatanzariti reopened this Jul 8, 2020
@mcatanzariti
Copy link
Member

Thank you so much for adding support for this!

However, there are two things that are problematic:

  1. MissingMemberHandling.Error does not work for polymorphic types; an exception with message Missing member '<name of the discriminator property>' always gets thrown for such a type.
  2. The exception message is probably going to be confusing to an end user ("but the member is not missing, it is right there!"). I think a message like Unrecognized property name '<name of property>' would help the user to more quickly realize what is wrong.

@SiggyBar I think I need an example with sample code for this one!

@SigmundVik
Copy link
Author

@mcatanzariti I created an example which produces the erroneous exception on this line.

@SigmundVik
Copy link
Author

This works great now, thanks again!

I think it would make sense to add Support for MissingMemberHandling to the feature list in README.md 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants