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

Make it easier to ignore specific errors when using the new parsers #2550

Closed
ewoutkramer opened this issue Jul 27, 2023 · 0 comments
Closed
Assignees

Comments

@ewoutkramer
Copy link
Member

When parsing finishes with issues, a DeserializationFailedException is thrown. This will signal to most people that deserialization has failed. However, this is not actually the intent: some of the issues found may be acceptable to the caller. Also, it is unclear that parsing continues until all issues are found, and that a poco is returned in the PartialResult property of the exception. Even when users would realize this, you'd still have to filter the issues for acceptable issues or real errors.

To make this easier to do, I propose to extend the current configuration interface of the System.Text.Json parsers like so:

var serializerOptions = new JsonSerializerOptions()
     .ForFhir()
     .Ignoring("JSON004", "JSON005");

In addition we can re-use the "standard set" of ignorable errors from FhirSerializationEngineFactory:

var serializerOptions = new JsonSerializerOptions()
     .ForFhir()
     .WithLeniency(BackwardsCompatible/Ostrich/etc);

Beneath this small layer of System.Text.Json, we could also adapt the new JsonPocoDeserializer() class with comparable methods:

  • var resource = Deserialize(jsonText, out var issues);
  • var deserializer = new JsonPocoDeserializer().WithLeniency(....).
  • var deserializer = new JsonPocoDeserializer().Ignoring(....).

I like the WithLeniency, although we have a slightly different syntax for configuring the FhirClient. Maybe we should add WithLeniency there, and adopt the other concrete methods (WithBackwardsCompatibleSerializer). In any case, keep this aligned.

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