Stream: dotnet
Topic: How to skip unknown resource in metadata
Yunwei Wang (Apr 05 2018 at 15:42):
When reading metadata, my C# client throws exception because unknown resource in the metadata. That is a server issue which I cannot fix. Is there a way to skip exception and continue parsing the rest of metadata?
Brian Postlethwaite (Apr 05 2018 at 21:02):
Is that due to the resource type value in the conformance/capabilitystatement?
Grahame Grieve (Apr 05 2018 at 21:11):
yes. hapi made a custom resource up
Grahame Grieve (Apr 05 2018 at 21:11):
that version did anyway
Brian Postlethwaite (Apr 05 2018 at 22:09):
There is a parser settings object that you can pass to the serializer that has a AllowUnrecognizedEnums
property which will permit it to accept the invalid code value.
The resource will have a value populated in the string representation of the code underneath, however the native enumeration field will be null.
// Example to parse some content with invalid required binding code values var settings = new Hl7.Fhir.Serialization.ParserSettings() { AllowUnrecognizedEnums = true}; var parser = new Hl7.Fhir.Serialization.FhirXmlParser(settings); var resource = parser.Parse<CapabilityStatement>(xmlString); // And the same thing with the FHIR REST client var server = new FhirClient(fhirServerAddress); server.ParserSettings = settings; var conformance = server.Conformance();
or similar ;)
Yunwei Wang (Apr 05 2018 at 22:12):
That is great. Thank you @Brian Postlethwaite
Brian Postlethwaite (Apr 05 2018 at 22:13):
Just be careful with it, as it lets stuff get through you may not be expecting.
I don't recall how the "error/warning" gets through to you.
It might be up to you to handle.
Brian Postlethwaite (Apr 05 2018 at 22:14):
Just checked, it's quiet
if (!Settings.AllowUnrecognizedEnums) { if (EnumUtility.ParseLiteral((string)value, mappedProperty.ElementType) == null) throw Error.Format("Literal '{0}' is not a valid value for enumeration '{1}'".FormatWith(value, mappedProperty.ElementType.Name), _current); }
Last updated: Apr 12 2022 at 19:14 UTC