示例#1
0
        /// <summary>
        /// Deserialize JSON into a FHIR Communication#Payload
        /// </summary>
        public static void DeserializeJson(this Communication.PayloadComponent 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($"Communication.PayloadComponent >>> Communication#Payload.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    reader.Read();
                    current.DeserializeJsonProperty(ref reader, options, propertyName);
                }
            }

            throw new JsonException($"Communication.PayloadComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
示例#2
0
        /// <summary>
        /// Serialize a FHIR Communication#Payload into JSON
        /// </summary>
        public static void SerializeJson(this Communication.PayloadComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            // Component: Communication#Payload, Export: PayloadComponent, Base: BackboneElement (BackboneElement)
            ((Hl7.Fhir.Model.BackboneElement)current).SerializeJson(writer, options, false);

            if (current.Content != null)
            {
                switch (current.Content)
                {
                case FhirString v_FhirString:
                    writer.WriteString("contentString", v_FhirString.Value);
                    break;

                case Attachment v_Attachment:
                    writer.WritePropertyName("contentAttachment");
                    v_Attachment.SerializeJson(writer, options);
                    break;

                case ResourceReference v_ResourceReference:
                    writer.WritePropertyName("contentReference");
                    v_ResourceReference.SerializeJson(writer, options);
                    break;
                }
            }
            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
示例#3
0
        /// <summary>
        /// Deserialize JSON into a FHIR Communication#Payload
        /// </summary>
        public static void DeserializeJsonProperty(this Communication.PayloadComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "contentString":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.Content = new FhirString();
                    reader.Skip();
                }
                else
                {
                    current.Content = new FhirString(reader.GetString());
                }
                break;

            case "_contentString":
                if (current.Content == null)
                {
                    current.Content = new FhirString();
                }
                ((Hl7.Fhir.Model.Element)current.Content).DeserializeJson(ref reader, options);
                break;

            case "contentAttachment":
                current.Content = new Hl7.Fhir.Model.Attachment();
                ((Hl7.Fhir.Model.Attachment)current.Content).DeserializeJson(ref reader, options);
                break;

            case "contentReference":
                current.Content = new Hl7.Fhir.Model.ResourceReference();
                ((Hl7.Fhir.Model.ResourceReference)current.Content).DeserializeJson(ref reader, options);
                break;

            // Complex: payload, Export: PayloadComponent, Base: BackboneElement
            default:
                ((Hl7.Fhir.Model.BackboneElement)current).DeserializeJsonProperty(ref reader, options, propertyName);
                break;
            }
        }