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

            throw new JsonException($"Coverage.CostToBeneficiaryComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
Example #2
0
        /// <summary>
        /// Deserialize JSON into a FHIR Coverage#CostToBeneficiary
        /// </summary>
        public static void DeserializeJsonProperty(this Coverage.CostToBeneficiaryComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "type":
                current.Type = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.Type).DeserializeJson(ref reader, options);
                break;

            case "valueQuantity":
                current.Value = new Hl7.Fhir.Model.Quantity();
                ((Hl7.Fhir.Model.Quantity)current.Value).DeserializeJson(ref reader, options);
                break;

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

            case "exception":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"CostToBeneficiaryComponent error reading 'exception' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Exception = new List <Coverage.ExemptionComponent>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.Coverage.ExemptionComponent v_Exception = new Hl7.Fhir.Model.Coverage.ExemptionComponent();
                    v_Exception.DeserializeJson(ref reader, options);
                    current.Exception.Add(v_Exception);

                    if (!reader.Read())
                    {
                        throw new JsonException($"CostToBeneficiaryComponent error reading 'exception' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Exception.Count == 0)
                {
                    current.Exception = null;
                }
                break;

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

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

            if (current.Value != null)
            {
                switch (current.Value)
                {
                case Quantity v_Quantity:
                    writer.WritePropertyName("valueQuantity");
                    v_Quantity.SerializeJson(writer, options);
                    break;

                case Money v_Money:
                    writer.WritePropertyName("valueMoney");
                    v_Money.SerializeJson(writer, options);
                    break;
                }
            }
            if ((current.Exception != null) && (current.Exception.Count != 0))
            {
                writer.WritePropertyName("exception");
                writer.WriteStartArray();
                foreach (Coverage.ExemptionComponent val in current.Exception)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

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