/// <summary> /// Deserialize JSON into a FHIR List#Entry /// </summary> public static void DeserializeJson(this List.EntryComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options) { string propertyName; while (reader.Read()) { if (reader.TokenType == JsonTokenType.EndObject) { return; } if (reader.TokenType == JsonTokenType.PropertyName) { propertyName = reader.GetString(); if (Hl7.Fhir.Serialization.FhirSerializerOptions.Debug) { Console.WriteLine($"List.EntryComponent >>> List#Entry.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } reader.Read(); current.DeserializeJsonProperty(ref reader, options, propertyName); } } throw new JsonException($"List.EntryComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); }
/// <summary> /// Deserialize JSON into a FHIR List#Entry /// </summary> public static void DeserializeJsonProperty(this List.EntryComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName) { switch (propertyName) { case "flag": current.Flag = new Hl7.Fhir.Model.CodeableConcept(); ((Hl7.Fhir.Model.CodeableConcept)current.Flag).DeserializeJson(ref reader, options); break; case "deleted": if (reader.TokenType == JsonTokenType.Null) { current.DeletedElement = new FhirBoolean(); reader.Skip(); } else { current.DeletedElement = new FhirBoolean(reader.GetBoolean()); } break; case "_deleted": if (current.DeletedElement == null) { current.DeletedElement = new FhirBoolean(); } ((Hl7.Fhir.Model.Element)current.DeletedElement).DeserializeJson(ref reader, options); break; case "date": if (reader.TokenType == JsonTokenType.Null) { current.DateElement = new FhirDateTime(); reader.Skip(); } else { current.DateElement = new FhirDateTime(reader.GetString()); } break; case "_date": if (current.DateElement == null) { current.DateElement = new FhirDateTime(); } ((Hl7.Fhir.Model.Element)current.DateElement).DeserializeJson(ref reader, options); break; case "item": current.Item = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Item).DeserializeJson(ref reader, options); break; // Complex: entry, Export: EntryComponent, Base: BackboneElement default: ((Hl7.Fhir.Model.BackboneElement)current).DeserializeJsonProperty(ref reader, options, propertyName); break; } }
private IResource CreateTestList() { var list = new List { Id = "test" }; var entryComponent = new List.EntryComponent(); entryComponent.Item = new ResourceReference("MedicationStatement/test"); list.Entry.Add(entryComponent); return(list.ToIResource()); }
/// <summary> /// Serialize a FHIR List#Entry into JSON /// </summary> public static void SerializeJson(this List.EntryComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true) { if (includeStartObject) { writer.WriteStartObject(); } // Component: List#Entry, Export: EntryComponent, Base: BackboneElement (BackboneElement) ((Hl7.Fhir.Model.BackboneElement)current).SerializeJson(writer, options, false); if (current.Flag != null) { writer.WritePropertyName("flag"); current.Flag.SerializeJson(writer, options); } if (current.DeletedElement != null) { if (current.DeletedElement.Value != null) { writer.WriteBoolean("deleted", (bool)current.DeletedElement.Value); } if (current.DeletedElement.HasExtensions() || (!string.IsNullOrEmpty(current.DeletedElement.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, "_deleted", false, current.DeletedElement.Extension, current.DeletedElement.ElementId); } } if (current.DateElement != null) { if (!string.IsNullOrEmpty(current.DateElement.Value)) { writer.WriteString("date", current.DateElement.Value); } if (current.DateElement.HasExtensions() || (!string.IsNullOrEmpty(current.DateElement.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, "_date", false, current.DateElement.Extension, current.DateElement.ElementId); } } writer.WritePropertyName("item"); current.Item.SerializeJson(writer, options); if (includeStartObject) { writer.WriteEndObject(); } }