Exemple #1
0
        /// <summary>
        /// Serialize a FHIR BackboneElement into JSON
        /// </summary>
        public static void SerializeJson(this BackboneElement current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            // Complex: BackboneElement, Export: BackboneElement, Base: Element (Element)
            ((Hl7.Fhir.Model.Element)current).SerializeJson(writer, options, false);

            if ((current.ModifierExtension != null) && (current.ModifierExtension.Count != 0))
            {
                writer.WritePropertyName("modifierExtension");
                writer.WriteStartArray();
                foreach (Extension val in current.ModifierExtension)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Exemple #2
0
        /// <summary>
        /// Deserialize JSON into a FHIR BackboneElement
        /// </summary>
        public static void DeserializeJson(this BackboneElement 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($"BackboneElement >>> BackboneElement.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    reader.Read();
                    current.DeserializeJsonProperty(ref reader, options, propertyName);
                }
            }

            throw new JsonException($"BackboneElement: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
Exemple #3
0
        /// <summary>
        /// Deserialize JSON into a FHIR BackboneElement
        /// </summary>
        public static void DeserializeJsonProperty(this BackboneElement current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "modifierExtension":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"BackboneElement error reading 'modifierExtension' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.ModifierExtension = new List <Extension>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.Extension v_ModifierExtension = new Hl7.Fhir.Model.Extension();
                    v_ModifierExtension.DeserializeJson(ref reader, options);
                    current.ModifierExtension.Add(v_ModifierExtension);

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

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

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