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

JsonSerializerOptions().ForFhir ... .Deserialize<Bundle>() Throws in 5.3.0 #2604

Closed
marked23 opened this issue Oct 12, 2023 · 3 comments
Closed

Comments

@marked23
Copy link

Describe the bug
Deserializing a Bundle document in 5.3.0-R4 does not work for me.
It worked in 4.3.0-R4.

var bundle = new Bundle();
var options = new JsonSerializerOptions().ForFhir(typeof(Bundle).Assembly);
bundle = JsonSerializer.Deserialize<Bundle>(jsonString, options);

To Reproduce
Using 5.3.0-R4

  1. Prepare a Bundle as a json string.
  2. Use the code snippet above to deserialize it.
  3. Experience a DeserializationFailedException

Expected behavior
Deserialization using 5.3.0 works successfully, as it does in 4.3.0.

Screenshots
If applicable, add screenshots to help explain your problem.

Version used:

  • FHIR Version: R4
  • Version: 5.3.0
@marked23
Copy link
Author

marked23 commented Oct 12, 2023

For some reason, I can't upload files to github... so sharing the error messages here.

{
	"Exceptions": [
		{
			"IssueSeverity": 0,
			"IssueType": 1,
			"BaseErrorMessage": "Unknown type 'Location' found in 'resourceType' property.",
			"LineNumber": 7,
			"Position": 20,
			"InstancePath": "Bundle.entry[0].resource",
			"ErrorCode": "JSON116",
			"Message": "Unknown type 'Location' found in 'resourceType' property. At Bundle.entry[0].resource, line 7, position 20",
			"Data": {},
			"InnerException": null,
			"HelpLink": null,
			"Source": null,
			"HResult": -2146233088,
			"StackTrace": null
		},
		{
			"IssueSeverity": 0,
			"IssueType": 1,
			"BaseErrorMessage": "Unknown type 'Organization' found in 'resourceType' property.",
			"LineNumber": 43,
			"Position": 20,
			"InstancePath": "Bundle.entry[1].resource",
			"ErrorCode": "JSON116",
			"Message": "Unknown type 'Organization' found in 'resourceType' property. At Bundle.entry[1].resource, line 43, position 20",
			"Data": {},
			"InnerException": null,
			"HelpLink": null,
			"Source": null,
			"HResult": -2146233088,
			"StackTrace": null
		},
		{
			"IssueSeverity": 0,
			"IssueType": 1,
			"BaseErrorMessage": "Unknown type 'Organization' found in 'resourceType' property.",
			"LineNumber": 60,
			"Position": 20,
			"InstancePath": "Bundle.entry[2].resource",
			"ErrorCode": "JSON116",
			"Message": "Unknown type 'Organization' found in 'resourceType' property. At Bundle.entry[2].resource, line 60, position 20",
			"Data": {},
			"InnerException": null,
			"HelpLink": null,
			"Source": null,
			"HResult": -2146233088,
			"StackTrace": null
		},
		{
			"IssueSeverity": 0,
			"IssueType": 1,
			"BaseErrorMessage": "Unknown type 'Organization' found in 'resourceType' property.",
			"LineNumber": 77,
			"Position": 20,
			"InstancePath": "Bundle.entry[3].resource",
			"ErrorCode": "JSON116",
			"Message": "Unknown type 'Organization' found in 'resourceType' property. At Bundle.entry[3].resource, line 77, position 20",
			"Data": {},
			"InnerException": null,
			"HelpLink": null,
			"Source": null,
			"HResult": -2146233088,
			"StackTrace": null
		},
		{
			"IssueSeverity": 0,
			"IssueType": 1,
			"BaseErrorMessage": "Unknown type 'HealthcareService' found in 'resourceType' property.",
			"LineNumber": 94,
			"Position": 20,
			"InstancePath": "Bundle.entry[4].resource",
			"ErrorCode": "JSON116",
			"Message": "Unknown type 'HealthcareService' found in 'resourceType' property. At Bundle.entry[4].resource, line 94, position 20",
			"Data": {},
			"InnerException": null,
			"HelpLink": null,
			"Source": null,
			"HResult": -2146233088,
			"StackTrace": null
		},
		{
			"IssueSeverity": 0,
			"IssueType": 1,
			"BaseErrorMessage": "Unknown type 'Practitioner' found in 'resourceType' property.",
			"LineNumber": 187,
			"Position": 20,
			"InstancePath": "Bundle.entry[5].resource",
			"ErrorCode": "JSON116",
			"Message": "Unknown type 'Practitioner' found in 'resourceType' property. At Bundle.entry[5].resource, line 187, position 20",
			"Data": {},
			"InnerException": null,
			"HelpLink": null,
			"Source": null,
			"HResult": -2146233088,
			"StackTrace": null
		},
		{
			"IssueSeverity": 0,
			"IssueType": 1,
			"BaseErrorMessage": "Unknown type 'PractitionerRole' found in 'resourceType' property.",
			"LineNumber": 409,
			"Position": 20,
			"InstancePath": "Bundle.entry[6].resource",
			"ErrorCode": "JSON116",
			"Message": "Unknown type 'PractitionerRole' found in 'resourceType' property. At Bundle.entry[6].resource, line 409, position 20",
			"Data": {},
			"InnerException": null,
			"HelpLink": null,
			"Source": null,
			"HResult": -2146233088,
			"StackTrace": null
		}
	],
	"Message": "One or more errors occurred. (Unknown type 'Location' found in 'resourceType' property. At Bundle.entry[0].resource, line 7, position 20) (Unknown type 'Organization' found in 'resourceType' property. At Bundle.entry[1].resource, line 43, position 20) (Unknown type 'Organization' found in 'resourceType' property. At Bundle.entry[2].resource, line 60, position 20) (Unknown type 'Organization' found in 'resourceType' property. At Bundle.entry[3].resource, line 77, position 20) (Unknown type 'HealthcareService' found in 'resourceType' property. At Bundle.entry[4].resource, line 94, position 20) (Unknown type 'Practitioner' found in 'resourceType' property. At Bundle.entry[5].resource, line 187, position 20) (Unknown type 'PractitionerRole' found in 'resourceType' property. At Bundle.entry[6].resource, line 409, position 20)"
}

@marked23
Copy link
Author

I think I have this figured out. Instead of Bundle I should be loading the assembly of one of the R4 models, like Practitioner or Organization, etc.

// works!
var bundle = new Bundle();
var options = new JsonSerializerOptions().ForFhir(typeof(Practitioner).Assembly);
bundle = JsonSerializer.Deserialize<Bundle>(jsonString, options);

@marcovisserFurore
Copy link
Member

Exactly! Even better is to use the ModelInfo.ModelInspector, like in our documentation. So:

var jsonInput = "{.....}";
var options = new JsonSerializerOptions().ForFhir(ModelInfo.ModelInspector);
var patient = JsonSerializer.Deserialize<Bundle>(jsonInput, options);

ModelInfo is a class that lives in the R4 library.

With this answer I close the issue.

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