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

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

            writer.WriteString("role", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.RoleElement.Value));

            writer.WritePropertyName("what");
            current.What.SerializeJson(writer, options);

            if ((current.Agent != null) && (current.Agent.Count != 0))
            {
                writer.WritePropertyName("agent");
                writer.WriteStartArray();
                foreach (Provenance.AgentComponent val in current.Agent)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Exemple #3
0
        /// <summary>
        /// Deserialize JSON into a FHIR Provenance#Entity
        /// </summary>
        public static void DeserializeJsonProperty(this Provenance.EntityComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "role":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.RoleElement = new Code <Hl7.Fhir.Model.Provenance.ProvenanceEntityRole>();
                    reader.Skip();
                }
                else
                {
                    current.RoleElement = new Code <Hl7.Fhir.Model.Provenance.ProvenanceEntityRole>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.Provenance.ProvenanceEntityRole>(reader.GetString()));
                }
                break;

            case "_role":
                if (current.RoleElement == null)
                {
                    current.RoleElement = new Code <Hl7.Fhir.Model.Provenance.ProvenanceEntityRole>();
                }
                ((Hl7.Fhir.Model.Element)current.RoleElement).DeserializeJson(ref reader, options);
                break;

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

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

                current.Agent = new List <Provenance.AgentComponent>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.Provenance.AgentComponent v_Agent = new Hl7.Fhir.Model.Provenance.AgentComponent();
                    v_Agent.DeserializeJson(ref reader, options);
                    current.Agent.Add(v_Agent);

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

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

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