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

            throw new JsonException($"Invoice.PriceComponentComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
예제 #2
0
        /// <summary>
        /// Deserialize JSON into a FHIR Invoice#PriceComponent
        /// </summary>
        public static void DeserializeJsonProperty(this Invoice.PriceComponentComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "type":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.TypeElement = new Code <Hl7.Fhir.Model.InvoicePriceComponentType>();
                    reader.Skip();
                }
                else
                {
                    current.TypeElement = new Code <Hl7.Fhir.Model.InvoicePriceComponentType>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.InvoicePriceComponentType>(reader.GetString()));
                }
                break;

            case "_type":
                if (current.TypeElement == null)
                {
                    current.TypeElement = new Code <Hl7.Fhir.Model.InvoicePriceComponentType>();
                }
                ((Hl7.Fhir.Model.Element)current.TypeElement).DeserializeJson(ref reader, options);
                break;

            case "code":
                current.Code = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.Code).DeserializeJson(ref reader, options);
                break;

            case "factor":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.FactorElement = new FhirDecimal();
                    reader.Skip();
                }
                else
                {
                    current.FactorElement = new FhirDecimal(reader.GetDecimal());
                }
                break;

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

            case "amount":
                current.Amount = new Hl7.Fhir.Model.Money();
                ((Hl7.Fhir.Model.Money)current.Amount).DeserializeJson(ref reader, options);
                break;

            // Complex: priceComponent, Export: PriceComponentComponent, Base: BackboneElement
            default:
                ((Hl7.Fhir.Model.BackboneElement)current).DeserializeJsonProperty(ref reader, options, propertyName);
                break;
            }
        }
예제 #3
0
        /// <summary>
        /// Serialize a FHIR Invoice#PriceComponent into JSON
        /// </summary>
        public static void SerializeJson(this Invoice.PriceComponentComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            // Component: Invoice#PriceComponent, Export: PriceComponentComponent, Base: BackboneElement (BackboneElement)
            ((Hl7.Fhir.Model.BackboneElement)current).SerializeJson(writer, options, false);

            writer.WriteString("type", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.TypeElement.Value));

            if (current.Code != null)
            {
                writer.WritePropertyName("code");
                current.Code.SerializeJson(writer, options);
            }

            if (current.FactorElement != null)
            {
                if (current.FactorElement.Value != null)
                {
                    writer.WriteNumber("factor", (decimal)current.FactorElement.Value);
                }
                if (current.FactorElement.HasExtensions() || (!string.IsNullOrEmpty(current.FactorElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_factor", false, current.FactorElement.Extension, current.FactorElement.ElementId);
                }
            }

            if (current.Amount != null)
            {
                writer.WritePropertyName("amount");
                current.Amount.SerializeJson(writer, options);
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }