-
Notifications
You must be signed in to change notification settings - Fork 345
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
FHIR JSON Serializer Problems with a custom resource #2658
Comments
Refinement:
|
Should not the two serializers behave the same?The two (de)serializers are inherently different, and the "legacy" element model (serializer 1) will generally accept more (usually non-fhir-compliant) cases. We recommend using the newer ones (serializer 2) for more accurate error reporting I do not understand the "Element 'xx' must not repeat" messages.After some testing of your code I found that this is due to the Active/Name property of your FhirWorkspace class never being null. Basically, our SDK checks if a property "already" has a value, and if so, throws an error if that property is not a collection. To prevent this error from being thrown, simply initialize the FhirBoolean to null if the internal boolean was originally null. The same counts for the name (although .NET's nullability annotations are inconsistent between these types). A fix would be along the lines of: [FhirElement("name", Order = 90)]
public FhirString? Name
{
get => _original.Name is not null ? new FhirString(_original.Name) : null;
set => _original.Name = value?.Value;
}
[DataMember]
[FhirElement("active", Order = 100)]
public FhirBoolean? Active
{
get => _original.Active.HasValue ? new FhirBoolean(_original.Active) : null;
set => _original.Active = value?.Value;
} Is it really not allowed to have an entity without any property value?This is technically allowed. Our implementation ignores the resource if it is empty and throws a DeserializationFailedException with issueSeverity "Warning". You can safely catch this exception. Why empty strings are a problem?
|
Discussed in #2579
Originally posted by Sneedd September 1, 2023
Help! Been stuck a while now. Tried different approaches to make it work, but so far nothing worked.
Basically I am trying to serialize and deserialize an custom resource. Tried the System.Text.Json and Newtonsoft approach.
Here is my code, if you like to try it out: Create a new MSTest .NET6 project, add the Hl7.Fhir.R4 (v5.3.0) library and paste the following code. I added the results over the tests, where 5 of 8 are failing.
So my problems are:
The text was updated successfully, but these errors were encountered: