Beispiel #1
0
 public void WriteBoolean(string propertyName, bool value, bool escape = true)
 => _writer.WriteBoolean(propertyName, value, escape);
Beispiel #2
0
        /// <summary>
        /// Serialize to a JSON object
        /// </summary>
        public new void SerializeJson(Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            if (!string.IsNullOrEmpty(ResourceType))
            {
                writer.WriteString("resourceType", (string)ResourceType !);
            }


            ((fhirCsR4.Models.DomainResource) this).SerializeJson(writer, options, false);

            if (!string.IsNullOrEmpty(Url))
            {
                writer.WriteString("url", (string)Url !);
            }

            if (_Url != null)
            {
                writer.WritePropertyName("_url");
                _Url.SerializeJson(writer, options);
            }

            if ((Identifier != null) && (Identifier.Count != 0))
            {
                writer.WritePropertyName("identifier");
                writer.WriteStartArray();

                foreach (Identifier valIdentifier in Identifier)
                {
                    valIdentifier.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (!string.IsNullOrEmpty(Version))
            {
                writer.WriteString("version", (string)Version !);
            }

            if (_Version != null)
            {
                writer.WritePropertyName("_version");
                _Version.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Name))
            {
                writer.WriteString("name", (string)Name !);
            }

            if (_Name != null)
            {
                writer.WritePropertyName("_name");
                _Name.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Title))
            {
                writer.WriteString("title", (string)Title !);
            }

            if (_Title != null)
            {
                writer.WritePropertyName("_title");
                _Title.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Subtitle))
            {
                writer.WriteString("subtitle", (string)Subtitle !);
            }

            if (_Subtitle != null)
            {
                writer.WritePropertyName("_subtitle");
                _Subtitle.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Status))
            {
                writer.WriteString("status", (string)Status !);
            }

            if (_Status != null)
            {
                writer.WritePropertyName("_status");
                _Status.SerializeJson(writer, options);
            }

            if (Experimental != null)
            {
                writer.WriteBoolean("experimental", (bool)Experimental !);
            }

            if (SubjectCodeableConcept != null)
            {
                writer.WritePropertyName("subjectCodeableConcept");
                SubjectCodeableConcept.SerializeJson(writer, options);
            }

            if (SubjectReference != null)
            {
                writer.WritePropertyName("subjectReference");
                SubjectReference.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Date))
            {
                writer.WriteString("date", (string)Date !);
            }

            if (_Date != null)
            {
                writer.WritePropertyName("_date");
                _Date.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Publisher))
            {
                writer.WriteString("publisher", (string)Publisher !);
            }

            if (_Publisher != null)
            {
                writer.WritePropertyName("_publisher");
                _Publisher.SerializeJson(writer, options);
            }

            if ((Contact != null) && (Contact.Count != 0))
            {
                writer.WritePropertyName("contact");
                writer.WriteStartArray();

                foreach (ContactDetail valContact in Contact)
                {
                    valContact.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (!string.IsNullOrEmpty(Description))
            {
                writer.WriteString("description", (string)Description !);
            }

            if (_Description != null)
            {
                writer.WritePropertyName("_description");
                _Description.SerializeJson(writer, options);
            }

            if ((UseContext != null) && (UseContext.Count != 0))
            {
                writer.WritePropertyName("useContext");
                writer.WriteStartArray();

                foreach (UsageContext valUseContext in UseContext)
                {
                    valUseContext.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Jurisdiction != null) && (Jurisdiction.Count != 0))
            {
                writer.WritePropertyName("jurisdiction");
                writer.WriteStartArray();

                foreach (CodeableConcept valJurisdiction in Jurisdiction)
                {
                    valJurisdiction.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (!string.IsNullOrEmpty(Purpose))
            {
                writer.WriteString("purpose", (string)Purpose !);
            }

            if (_Purpose != null)
            {
                writer.WritePropertyName("_purpose");
                _Purpose.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Usage))
            {
                writer.WriteString("usage", (string)Usage !);
            }

            if (_Usage != null)
            {
                writer.WritePropertyName("_usage");
                _Usage.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Copyright))
            {
                writer.WriteString("copyright", (string)Copyright !);
            }

            if (_Copyright != null)
            {
                writer.WritePropertyName("_copyright");
                _Copyright.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(ApprovalDate))
            {
                writer.WriteString("approvalDate", (string)ApprovalDate !);
            }

            if (_ApprovalDate != null)
            {
                writer.WritePropertyName("_approvalDate");
                _ApprovalDate.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(LastReviewDate))
            {
                writer.WriteString("lastReviewDate", (string)LastReviewDate !);
            }

            if (_LastReviewDate != null)
            {
                writer.WritePropertyName("_lastReviewDate");
                _LastReviewDate.SerializeJson(writer, options);
            }

            if (EffectivePeriod != null)
            {
                writer.WritePropertyName("effectivePeriod");
                EffectivePeriod.SerializeJson(writer, options);
            }

            if ((Topic != null) && (Topic.Count != 0))
            {
                writer.WritePropertyName("topic");
                writer.WriteStartArray();

                foreach (CodeableConcept valTopic in Topic)
                {
                    valTopic.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Author != null) && (Author.Count != 0))
            {
                writer.WritePropertyName("author");
                writer.WriteStartArray();

                foreach (ContactDetail valAuthor in Author)
                {
                    valAuthor.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Editor != null) && (Editor.Count != 0))
            {
                writer.WritePropertyName("editor");
                writer.WriteStartArray();

                foreach (ContactDetail valEditor in Editor)
                {
                    valEditor.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Reviewer != null) && (Reviewer.Count != 0))
            {
                writer.WritePropertyName("reviewer");
                writer.WriteStartArray();

                foreach (ContactDetail valReviewer in Reviewer)
                {
                    valReviewer.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Endorser != null) && (Endorser.Count != 0))
            {
                writer.WritePropertyName("endorser");
                writer.WriteStartArray();

                foreach (ContactDetail valEndorser in Endorser)
                {
                    valEndorser.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((RelatedArtifact != null) && (RelatedArtifact.Count != 0))
            {
                writer.WritePropertyName("relatedArtifact");
                writer.WriteStartArray();

                foreach (RelatedArtifact valRelatedArtifact in RelatedArtifact)
                {
                    valRelatedArtifact.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Trigger != null) && (Trigger.Count != 0))
            {
                writer.WritePropertyName("trigger");
                writer.WriteStartArray();

                foreach (TriggerDefinition valTrigger in Trigger)
                {
                    valTrigger.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Serialize to a JSON object
        /// </summary>
        public new void SerializeJson(Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }

            if (!string.IsNullOrEmpty(ResourceType))
            {
                writer.WriteString("resourceType", (string)ResourceType !);
            }


            ((Fhir.R4.Models.DomainResource) this).SerializeJson(writer, options, false);

            if (!string.IsNullOrEmpty(Url))
            {
                writer.WriteString("url", (string)Url !);
            }

            if (_Url != null)
            {
                writer.WritePropertyName("_url");
                _Url.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Version))
            {
                writer.WriteString("version", (string)Version !);
            }

            if (_Version != null)
            {
                writer.WritePropertyName("_version");
                _Version.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Name))
            {
                writer.WriteString("name", (string)Name !);
            }

            if (_Name != null)
            {
                writer.WritePropertyName("_name");
                _Name.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(DerivedFrom))
            {
                writer.WriteString("derivedFrom", (string)DerivedFrom !);
            }

            if (_DerivedFrom != null)
            {
                writer.WritePropertyName("_derivedFrom");
                _DerivedFrom.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Status))
            {
                writer.WriteString("status", (string)Status !);
            }

            if (_Status != null)
            {
                writer.WritePropertyName("_status");
                _Status.SerializeJson(writer, options);
            }

            if (Experimental != null)
            {
                writer.WriteBoolean("experimental", (bool)Experimental !);
            }

            if (!string.IsNullOrEmpty(Date))
            {
                writer.WriteString("date", (string)Date !);
            }

            if (_Date != null)
            {
                writer.WritePropertyName("_date");
                _Date.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Publisher))
            {
                writer.WriteString("publisher", (string)Publisher !);
            }

            if (_Publisher != null)
            {
                writer.WritePropertyName("_publisher");
                _Publisher.SerializeJson(writer, options);
            }

            if ((Contact != null) && (Contact.Count != 0))
            {
                writer.WritePropertyName("contact");
                writer.WriteStartArray();

                foreach (ContactDetail valContact in Contact)
                {
                    valContact.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (!string.IsNullOrEmpty(Description))
            {
                writer.WriteString("description", (string)Description !);
            }

            if (_Description != null)
            {
                writer.WritePropertyName("_description");
                _Description.SerializeJson(writer, options);
            }

            if ((UseContext != null) && (UseContext.Count != 0))
            {
                writer.WritePropertyName("useContext");
                writer.WriteStartArray();

                foreach (UsageContext valUseContext in UseContext)
                {
                    valUseContext.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Jurisdiction != null) && (Jurisdiction.Count != 0))
            {
                writer.WritePropertyName("jurisdiction");
                writer.WriteStartArray();

                foreach (CodeableConcept valJurisdiction in Jurisdiction)
                {
                    valJurisdiction.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (!string.IsNullOrEmpty(Purpose))
            {
                writer.WriteString("purpose", (string)Purpose !);
            }

            if (_Purpose != null)
            {
                writer.WritePropertyName("_purpose");
                _Purpose.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Code))
            {
                writer.WriteString("code", (string)Code !);
            }

            if (_Code != null)
            {
                writer.WritePropertyName("_code");
                _Code.SerializeJson(writer, options);
            }

            if ((Base != null) && (Base.Count != 0))
            {
                writer.WritePropertyName("base");
                writer.WriteStartArray();

                foreach (string valBase in Base)
                {
                    writer.WriteStringValue(valBase);
                }

                writer.WriteEndArray();
            }

            if ((_Base != null) && (_Base.Count != 0))
            {
                writer.WritePropertyName("_base");
                writer.WriteStartArray();

                foreach (Element val_Base in _Base)
                {
                    val_Base.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (!string.IsNullOrEmpty(Type))
            {
                writer.WriteString("type", (string)Type !);
            }

            if (_Type != null)
            {
                writer.WritePropertyName("_type");
                _Type.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Expression))
            {
                writer.WriteString("expression", (string)Expression !);
            }

            if (_Expression != null)
            {
                writer.WritePropertyName("_expression");
                _Expression.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Xpath))
            {
                writer.WriteString("xpath", (string)Xpath !);
            }

            if (_Xpath != null)
            {
                writer.WritePropertyName("_xpath");
                _Xpath.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(XpathUsage))
            {
                writer.WriteString("xpathUsage", (string)XpathUsage !);
            }

            if (_XpathUsage != null)
            {
                writer.WritePropertyName("_xpathUsage");
                _XpathUsage.SerializeJson(writer, options);
            }

            if ((Target != null) && (Target.Count != 0))
            {
                writer.WritePropertyName("target");
                writer.WriteStartArray();

                foreach (string valTarget in Target)
                {
                    writer.WriteStringValue(valTarget);
                }

                writer.WriteEndArray();
            }

            if ((_Target != null) && (_Target.Count != 0))
            {
                writer.WritePropertyName("_target");
                writer.WriteStartArray();

                foreach (Element val_Target in _Target)
                {
                    val_Target.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (MultipleOr != null)
            {
                writer.WriteBoolean("multipleOr", (bool)MultipleOr !);
            }

            if (MultipleAnd != null)
            {
                writer.WriteBoolean("multipleAnd", (bool)MultipleAnd !);
            }

            if ((Comparator != null) && (Comparator.Count != 0))
            {
                writer.WritePropertyName("comparator");
                writer.WriteStartArray();

                foreach (string valComparator in Comparator)
                {
                    writer.WriteStringValue(valComparator);
                }

                writer.WriteEndArray();
            }

            if ((_Comparator != null) && (_Comparator.Count != 0))
            {
                writer.WritePropertyName("_comparator");
                writer.WriteStartArray();

                foreach (Element val_Comparator in _Comparator)
                {
                    val_Comparator.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Modifier != null) && (Modifier.Count != 0))
            {
                writer.WritePropertyName("modifier");
                writer.WriteStartArray();

                foreach (string valModifier in Modifier)
                {
                    writer.WriteStringValue(valModifier);
                }

                writer.WriteEndArray();
            }

            if ((_Modifier != null) && (_Modifier.Count != 0))
            {
                writer.WritePropertyName("_modifier");
                writer.WriteStartArray();

                foreach (Element val_Modifier in _Modifier)
                {
                    val_Modifier.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Chain != null) && (Chain.Count != 0))
            {
                writer.WritePropertyName("chain");
                writer.WriteStartArray();

                foreach (string valChain in Chain)
                {
                    writer.WriteStringValue(valChain);
                }

                writer.WriteEndArray();
            }

            if ((_Chain != null) && (_Chain.Count != 0))
            {
                writer.WritePropertyName("_chain");
                writer.WriteStartArray();

                foreach (Element val_Chain in _Chain)
                {
                    val_Chain.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Component != null) && (Component.Count != 0))
            {
                writer.WritePropertyName("component");
                writer.WriteStartArray();

                foreach (SearchParameterComponent valComponent in Component)
                {
                    valComponent.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

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

            writer.WriteString("url", current.Url.Trim());

            if (current.Value != null)
            {
                switch (current.Value)
                {
                case Base64Binary v_Base64Binary:
                    if (v_Base64Binary != null)
                    {
                        if (v_Base64Binary.Value != null)
                        {
                            writer.WriteString("valueBase64Binary", System.Convert.ToBase64String(v_Base64Binary.Value));
                        }
                        if (v_Base64Binary.HasExtensions() || (!string.IsNullOrEmpty(v_Base64Binary.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueBase64Binary", false, v_Base64Binary.Extension, v_Base64Binary.ElementId);
                        }
                    }
                    break;

                case FhirBoolean v_FhirBoolean:
                    if (v_FhirBoolean != null)
                    {
                        if (v_FhirBoolean.Value != null)
                        {
                            writer.WriteBoolean("valueBoolean", (bool)v_FhirBoolean.Value);
                        }
                        if (v_FhirBoolean.HasExtensions() || (!string.IsNullOrEmpty(v_FhirBoolean.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueBoolean", false, v_FhirBoolean.Extension, v_FhirBoolean.ElementId);
                        }
                    }
                    break;

                case Canonical v_Canonical:
                    if (v_Canonical != null)
                    {
                        if (!string.IsNullOrEmpty(v_Canonical.Value))
                        {
                            writer.WriteString("valueCanonical", v_Canonical.Value);
                        }
                        if (v_Canonical.HasExtensions() || (!string.IsNullOrEmpty(v_Canonical.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueCanonical", false, v_Canonical.Extension, v_Canonical.ElementId);
                        }
                    }
                    break;

                case Code v_Code:
                    if (v_Code != null)
                    {
                        if (!string.IsNullOrEmpty(v_Code.Value))
                        {
                            writer.WriteString("valueCode", v_Code.Value.Trim());
                        }
                        if (v_Code.HasExtensions() || (!string.IsNullOrEmpty(v_Code.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueCode", false, v_Code.Extension, v_Code.ElementId);
                        }
                    }
                    break;

                case Date v_Date:
                    if (v_Date != null)
                    {
                        if (!string.IsNullOrEmpty(v_Date.Value))
                        {
                            writer.WriteString("valueDate", v_Date.Value);
                        }
                        if (v_Date.HasExtensions() || (!string.IsNullOrEmpty(v_Date.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueDate", false, v_Date.Extension, v_Date.ElementId);
                        }
                    }
                    break;

                case FhirDateTime v_FhirDateTime:
                    if (v_FhirDateTime != null)
                    {
                        if (!string.IsNullOrEmpty(v_FhirDateTime.Value))
                        {
                            writer.WriteString("valueDateTime", v_FhirDateTime.Value);
                        }
                        if (v_FhirDateTime.HasExtensions() || (!string.IsNullOrEmpty(v_FhirDateTime.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueDateTime", false, v_FhirDateTime.Extension, v_FhirDateTime.ElementId);
                        }
                    }
                    break;

                case FhirDecimal v_FhirDecimal:
                    if (v_FhirDecimal != null)
                    {
                        if (v_FhirDecimal.Value != null)
                        {
                            writer.WriteNumber("valueDecimal", (decimal)v_FhirDecimal.Value);
                        }
                        if (v_FhirDecimal.HasExtensions() || (!string.IsNullOrEmpty(v_FhirDecimal.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueDecimal", false, v_FhirDecimal.Extension, v_FhirDecimal.ElementId);
                        }
                    }
                    break;

                case Id v_Id:
                    if (v_Id != null)
                    {
                        if (!string.IsNullOrEmpty(v_Id.Value))
                        {
                            writer.WriteString("valueId", v_Id.Value);
                        }
                        if (v_Id.HasExtensions() || (!string.IsNullOrEmpty(v_Id.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueId", false, v_Id.Extension, v_Id.ElementId);
                        }
                    }
                    break;

                case Instant v_Instant:
                    if (v_Instant != null)
                    {
                        if (v_Instant.Value != null)
                        {
                            writer.WriteString("valueInstant", ((DateTimeOffset)v_Instant.Value).ToString("yyyy-MM-dd'T'HH:mm:ss.FFFFFFFK", System.Globalization.CultureInfo.InvariantCulture));
                        }
                        if (v_Instant.HasExtensions() || (!string.IsNullOrEmpty(v_Instant.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueInstant", false, v_Instant.Extension, v_Instant.ElementId);
                        }
                    }
                    break;

                case Integer v_Integer:
                    if (v_Integer != null)
                    {
                        if (v_Integer.Value != null)
                        {
                            writer.WriteNumber("valueInteger", (int)v_Integer.Value);
                        }
                        if (v_Integer.HasExtensions() || (!string.IsNullOrEmpty(v_Integer.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueInteger", false, v_Integer.Extension, v_Integer.ElementId);
                        }
                    }
                    break;

                case Markdown v_Markdown:
                    if (v_Markdown != null)
                    {
                        if (!string.IsNullOrEmpty(v_Markdown.Value))
                        {
                            writer.WriteString("valueMarkdown", v_Markdown.Value);
                        }
                        if (v_Markdown.HasExtensions() || (!string.IsNullOrEmpty(v_Markdown.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueMarkdown", false, v_Markdown.Extension, v_Markdown.ElementId);
                        }
                    }
                    break;

                case Oid v_Oid:
                    if (v_Oid != null)
                    {
                        if (!string.IsNullOrEmpty(v_Oid.Value))
                        {
                            writer.WriteString("valueOid", v_Oid.Value);
                        }
                        if (v_Oid.HasExtensions() || (!string.IsNullOrEmpty(v_Oid.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueOid", false, v_Oid.Extension, v_Oid.ElementId);
                        }
                    }
                    break;

                case PositiveInt v_PositiveInt:
                    if (v_PositiveInt != null)
                    {
                        if (v_PositiveInt.Value != null)
                        {
                            writer.WriteNumber("valuePositiveInt", (int)v_PositiveInt.Value);
                        }
                        if (v_PositiveInt.HasExtensions() || (!string.IsNullOrEmpty(v_PositiveInt.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valuePositiveInt", false, v_PositiveInt.Extension, v_PositiveInt.ElementId);
                        }
                    }
                    break;

                case FhirString v_FhirString:
                    if (v_FhirString != null)
                    {
                        if (!string.IsNullOrEmpty(v_FhirString.Value))
                        {
                            writer.WriteString("valueString", v_FhirString.Value);
                        }
                        if (v_FhirString.HasExtensions() || (!string.IsNullOrEmpty(v_FhirString.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueString", false, v_FhirString.Extension, v_FhirString.ElementId);
                        }
                    }
                    break;

                case Time v_Time:
                    writer.WritePropertyName("valueTime");
                    v_Time.SerializeJson(writer, options);
                    break;

                case UnsignedInt v_UnsignedInt:
                    if (v_UnsignedInt != null)
                    {
                        if (v_UnsignedInt.Value != null)
                        {
                            writer.WriteNumber("valueUnsignedInt", (int)v_UnsignedInt.Value);
                        }
                        if (v_UnsignedInt.HasExtensions() || (!string.IsNullOrEmpty(v_UnsignedInt.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueUnsignedInt", false, v_UnsignedInt.Extension, v_UnsignedInt.ElementId);
                        }
                    }
                    break;

                case FhirUri v_FhirUri:
                    if (v_FhirUri != null)
                    {
                        if (!string.IsNullOrEmpty(v_FhirUri.Value))
                        {
                            writer.WriteString("valueUri", v_FhirUri.Value);
                        }
                        if (v_FhirUri.HasExtensions() || (!string.IsNullOrEmpty(v_FhirUri.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueUri", false, v_FhirUri.Extension, v_FhirUri.ElementId);
                        }
                    }
                    break;

                case FhirUrl v_FhirUrl:
                    if (v_FhirUrl != null)
                    {
                        if (!string.IsNullOrEmpty(v_FhirUrl.Value))
                        {
                            writer.WriteString("valueUrl", v_FhirUrl.Value);
                        }
                        if (v_FhirUrl.HasExtensions() || (!string.IsNullOrEmpty(v_FhirUrl.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueUrl", false, v_FhirUrl.Extension, v_FhirUrl.ElementId);
                        }
                    }
                    break;

                case Uuid v_Uuid:
                    if (v_Uuid != null)
                    {
                        if (!string.IsNullOrEmpty(v_Uuid.Value))
                        {
                            writer.WriteString("valueUuid", v_Uuid.Value);
                        }
                        if (v_Uuid.HasExtensions() || (!string.IsNullOrEmpty(v_Uuid.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueUuid", false, v_Uuid.Extension, v_Uuid.ElementId);
                        }
                    }
                    break;

                case Address v_Address:
                    writer.WritePropertyName("valueAddress");
                    v_Address.SerializeJson(writer, options);
                    break;

                case Age v_Age:
                    writer.WritePropertyName("valueAge");
                    v_Age.SerializeJson(writer, options);
                    break;

                case Annotation v_Annotation:
                    writer.WritePropertyName("valueAnnotation");
                    v_Annotation.SerializeJson(writer, options);
                    break;

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

                case CodeableConcept v_CodeableConcept:
                    writer.WritePropertyName("valueCodeableConcept");
                    v_CodeableConcept.SerializeJson(writer, options);
                    break;

                case Coding v_Coding:
                    writer.WritePropertyName("valueCoding");
                    v_Coding.SerializeJson(writer, options);
                    break;

                case ContactPoint v_ContactPoint:
                    writer.WritePropertyName("valueContactPoint");
                    v_ContactPoint.SerializeJson(writer, options);
                    break;

                case Count v_Count:
                    writer.WritePropertyName("valueCount");
                    v_Count.SerializeJson(writer, options);
                    break;

                case Distance v_Distance:
                    writer.WritePropertyName("valueDistance");
                    v_Distance.SerializeJson(writer, options);
                    break;

                case Duration v_Duration:
                    writer.WritePropertyName("valueDuration");
                    v_Duration.SerializeJson(writer, options);
                    break;

                case HumanName v_HumanName:
                    writer.WritePropertyName("valueHumanName");
                    v_HumanName.SerializeJson(writer, options);
                    break;

                case Identifier v_Identifier:
                    writer.WritePropertyName("valueIdentifier");
                    v_Identifier.SerializeJson(writer, options);
                    break;

                case Money v_Money:
                    writer.WritePropertyName("valueMoney");
                    v_Money.SerializeJson(writer, options);
                    break;

                case Period v_Period:
                    writer.WritePropertyName("valuePeriod");
                    v_Period.SerializeJson(writer, options);
                    break;

                case Quantity v_Quantity:
                    writer.WritePropertyName("valueQuantity");
                    v_Quantity.SerializeJson(writer, options);
                    break;

                case Range v_Range:
                    writer.WritePropertyName("valueRange");
                    v_Range.SerializeJson(writer, options);
                    break;

                case Ratio v_Ratio:
                    writer.WritePropertyName("valueRatio");
                    v_Ratio.SerializeJson(writer, options);
                    break;

                case ResourceReference v_ResourceReference:
                    writer.WritePropertyName("valueReference");
                    v_ResourceReference.SerializeJson(writer, options);
                    break;

                case SampledData v_SampledData:
                    writer.WritePropertyName("valueSampledData");
                    v_SampledData.SerializeJson(writer, options);
                    break;

                case Signature v_Signature:
                    writer.WritePropertyName("valueSignature");
                    v_Signature.SerializeJson(writer, options);
                    break;

                case Timing v_Timing:
                    writer.WritePropertyName("valueTiming");
                    v_Timing.SerializeJson(writer, options);
                    break;

                case ContactDetail v_ContactDetail:
                    writer.WritePropertyName("valueContactDetail");
                    v_ContactDetail.SerializeJson(writer, options);
                    break;

                case Contributor v_Contributor:
                    writer.WritePropertyName("valueContributor");
                    v_Contributor.SerializeJson(writer, options);
                    break;

                case DataRequirement v_DataRequirement:
                    writer.WritePropertyName("valueDataRequirement");
                    v_DataRequirement.SerializeJson(writer, options);
                    break;

                case Expression v_Expression:
                    writer.WritePropertyName("valueExpression");
                    v_Expression.SerializeJson(writer, options);
                    break;

                case ParameterDefinition v_ParameterDefinition:
                    writer.WritePropertyName("valueParameterDefinition");
                    v_ParameterDefinition.SerializeJson(writer, options);
                    break;

                case RelatedArtifact v_RelatedArtifact:
                    writer.WritePropertyName("valueRelatedArtifact");
                    v_RelatedArtifact.SerializeJson(writer, options);
                    break;

                case TriggerDefinition v_TriggerDefinition:
                    writer.WritePropertyName("valueTriggerDefinition");
                    v_TriggerDefinition.SerializeJson(writer, options);
                    break;

                case UsageContext v_UsageContext:
                    writer.WritePropertyName("valueUsageContext");
                    v_UsageContext.SerializeJson(writer, options);
                    break;

                case Dosage v_Dosage:
                    writer.WritePropertyName("valueDosage");
                    v_Dosage.SerializeJson(writer, options);
                    break;

                case Meta v_Meta:
                    writer.WritePropertyName("valueMeta");
                    v_Meta.SerializeJson(writer, options);
                    break;
                }
            }
            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Beispiel #5
0
        public override byte[] Serialize(IDictionary <string, object> values)
        {
            if (values == null || values.Count == 0)
            {
                return(Array.Empty <byte>());
            }

            using (var bufferWriter = new ArrayBufferWriter <byte>())
            {
                var writer = new Utf8JsonWriter(bufferWriter);
                writer.WriteStartObject();
                foreach (var(key, value) in values)
                {
                    if (value == null)
                    {
                        writer.WriteNull(key);
                        continue;
                    }

                    // We want to allow only simple types to be serialized.
                    if (!CanSerializeType(value.GetType()))
                    {
                        throw new InvalidOperationException(
                                  Resources.FormatTempData_CannotSerializeType(
                                      typeof(DefaultTempDataSerializer).FullName,
                                      value.GetType()));
                    }

                    switch (value)
                    {
                    case Enum _:
                        writer.WriteNumber(key, (int)value);
                        break;

                    case string stringValue:
                        writer.WriteString(key, stringValue);
                        break;

                    case int intValue:
                        writer.WriteNumber(key, intValue);
                        break;

                    case bool boolValue:
                        writer.WriteBoolean(key, boolValue);
                        break;

                    case DateTime dateTime:
                        writer.WriteString(key, dateTime.ToString("r", CultureInfo.InvariantCulture));
                        break;

                    case Guid guid:
                        writer.WriteString(key, guid.ToString("B", CultureInfo.InvariantCulture));
                        break;
                    }
                }
                writer.WriteEndObject();
                writer.Flush();

                return(bufferWriter.WrittenMemory.ToArray());
            }
        }
        public override string SanitizeTextBody(string contentType, string body)
        {
            if (contentType.Contains("json"))
            {
                try
                {
                    // Check for auth calls to readact any access tokens
                    var reader = new Utf8JsonReader(Encoding.UTF8.GetBytes(body).AsSpan(), true, new JsonReaderState());
                    if (JsonDocument.TryParseValue(ref reader, out JsonDocument doc) &&
                        doc.RootElement.GetProperty("token_type").GetString() == "Bearer")
                    {
                        // If we found an auth call, sanitize it
                        using (var stream = new System.IO.MemoryStream())
                        {
                            using (var writer = new Utf8JsonWriter(stream))
                            {
                                writer.WriteStartObject();
                                foreach (JsonProperty property in doc.RootElement.EnumerateObject())
                                {
                                    switch (doc.RootElement.GetProperty(property.Name).ValueKind)
                                    {
                                    case JsonValueKind.Null:
                                        writer.WriteNull(property.Name);
                                        break;

                                    case JsonValueKind.True:
                                        writer.WriteBoolean(property.Name, true);
                                        break;

                                    case JsonValueKind.False:
                                        writer.WriteBoolean(property.Name, false);
                                        break;

                                    case JsonValueKind.Number:
                                        writer.WriteNumber(property.Name, property.Value.GetDouble());
                                        break;

                                    case JsonValueKind.String:
                                        writer.WriteString(
                                            property.Name,
                                            property.Name == "access_token" ?
                                            SanitizeValue :
                                            property.Value.GetString());
                                        break;
                                        // Ignore nested objects and arrays...
                                    }
                                }
                                writer.WriteEndObject();
                            }
                            return(Encoding.UTF8.GetString(stream.ToArray()));
                        }
                    }
                }
                catch
                {
                }
            }
            else if (contentType.Contains("urlencoded"))
            {
                try
                {
                    // If it's been URL encoded, make sure it doesn't contain
                    // a client_secret
                    var builder = new UriBuilder()
                    {
                        Query = body
                    };
                    var query = new UriQueryParamsCollection(body);
                    if (query.ContainsKey("client_secret"))
                    {
                        query["client_secret"] = SanitizeValue;
                    }
                    return(query.ToString());
                }
                catch
                {
                }
            }

            // If anything goes wrong, don't sanitize
            return(body);
        }
 void IJsonSerializable.WriteProperties(Utf8JsonWriter json)
 {
     json.WriteBoolean(CancellationRequestedPropertyNameBytes, _cancellationRequested);
 }
Beispiel #8
0
        private static void Write(Utf8JsonWriter writer, string key, object value)
        {
            // Only write known types to the JSON
            switch (value)
            {
            case null:
                return;

            case byte byteValue:
                writer.WriteNumber(key, byteValue);
                break;

            case bool boolValue:
                writer.WriteBoolean(key, boolValue);
                break;

            case char charValue:
                writer.WriteString(key, charValue.ToString());
                break;

            case decimal decimalValue:
                writer.WriteNumber(key, decimalValue);
                break;

            case double doubleValue:
                writer.WriteNumber(key, doubleValue);
                break;

            case float floatValue:
                writer.WriteNumber(key, floatValue);
                break;

            case int intValue:
                writer.WriteNumber(key, intValue);
                break;

            case long longValue:
                writer.WriteNumber(key, longValue);
                break;

            case short shortValue:
                writer.WriteNumber(key, shortValue);
                break;

            case sbyte sbyteValue:
                writer.WriteNumber(key, sbyteValue);
                break;

            case uint uintValue:
                writer.WriteNumber(key, uintValue);
                break;

            case ulong ulongValue:
                writer.WriteNumber(key, ulongValue);
                break;

            case ushort ushortValue:
                writer.WriteNumber(key, ushortValue);
                break;

            case Guid guidValue:
                writer.WriteString(key, guidValue);
                break;

            case DateTime dateTimeValue:
                writer.WriteString(key, dateTimeValue);
                break;

            case DateTimeOffset dateTimeOffsetValue:
                writer.WriteString(key, dateTimeOffsetValue);
                break;

            case string stringValue:
                writer.WriteString(key, stringValue);
                break;
            }
        }
Beispiel #9
0
        public string ExecuteJson(string sql)
        {
            string            json;
            JsonWriterOptions options = new JsonWriterOptions {
                Indented = true
            };

            using (MemoryStream stream = new MemoryStream())
            {
                using (Utf8JsonWriter writer = new Utf8JsonWriter(stream, options))
                {
                    writer.WriteStartArray();
                    using (SqlConnection connection = new SqlConnection(MetadataService.ConnectionString))
                        using (SqlCommand command = new SqlCommand(sql, connection))
                        {
                            connection.Open();

                            using (SqlDataReader reader = command.ExecuteReader())
                            {
                                var schema = reader.GetColumnSchema();
                                while (reader.Read())
                                {
                                    writer.WriteStartObject();
                                    for (int c = 0; c < schema.Count; c++)
                                    {
                                        object value      = reader[c];
                                        string typeName   = schema[c].DataTypeName;
                                        string columnName = schema[c].ColumnName;
                                        int    valueSize  = 0;
                                        if (schema[c].ColumnSize.HasValue)
                                        {
                                            valueSize = schema[c].ColumnSize.Value;
                                        }
                                        if (value == DBNull.Value)
                                        {
                                            writer.WriteNull(columnName);
                                        }
                                        else if (DbUtilities.IsString(typeName))
                                        {
                                            writer.WriteString(columnName, (string)value);
                                        }
                                        else if (DbUtilities.IsDateTime(typeName))
                                        {
                                            writer.WriteString(columnName, ((DateTime)value).ToString("yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture));
                                        }
                                        else if (DbUtilities.IsVersion(typeName))
                                        {
                                            writer.WriteString(columnName, $"0x{DbUtilities.ByteArrayToString((byte[])value)}");
                                        }
                                        else if (DbUtilities.IsBoolean(typeName, valueSize))
                                        {
                                            if (typeName == "bit")
                                            {
                                                writer.WriteBoolean(columnName, (bool)value);
                                            }
                                            else // binary(1)
                                            {
                                                writer.WriteBoolean(columnName, DbUtilities.GetInt32((byte[])value) == 0 ? false : true);
                                            }
                                        }
                                        else if (DbUtilities.IsNumber(typeName, valueSize))
                                        {
                                            if (typeName == "binary" || typeName == "varbinary") // binary(4) | varbinary(4)
                                            {
                                                writer.WriteNumber(columnName, DbUtilities.GetInt32((byte[])value));
                                            }
                                            else
                                            {
                                                writer.WriteNumber(columnName, (decimal)value);
                                            }
                                        }
                                        else if (DbUtilities.IsUUID(typeName, valueSize))
                                        {
                                            writer.WriteString(columnName, (new Guid((byte[])value)).ToString());
                                        }
                                        else if (DbUtilities.IsReference(typeName, valueSize))
                                        {
                                            byte[] reference = (byte[])value;
                                            int    code      = DbUtilities.GetInt32(reference[0..4]);
Beispiel #10
0
        public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config)
        {
            // ---------------开始解析对象--------------
            writer.WriteStartObject();
            // 1. 验证校验和
            if (!reader.CheckXorCodeVali)
            {
                writer.WriteString("检验和错误", $"{reader.RealCheckXorCode}!={reader.CalculateCheckXorCode}");
            }
            // 2.读取起始位置
            byte start = reader.ReadEnd();

            writer.WriteNumber($"[{start.ReadNumber()}]开始", start);
            var msgid = reader.ReadUInt16();

            writer.WriteNumber($"[{msgid.ReadNumber()}]消息Id", msgid);
            ushort messageBodyPropertyValue  = reader.ReadUInt16();
            var    headerMessageBodyProperty = new JT808HeaderMessageBodyProperty(messageBodyPropertyValue);

            //消息体属性对象 开始
            writer.WriteStartObject("消息体属性对象");
            ReadOnlySpan <char> messageBodyPropertyReadOnlySpan = messageBodyPropertyValue.ReadBinary();

            writer.WriteNumber($"[{messageBodyPropertyReadOnlySpan.ToString()}]消息体属性", messageBodyPropertyValue);
            if (headerMessageBodyProperty.VersionFlag)
            {
                reader.Version = JT808Version.JTT2019;
                writer.WriteNumber("[bit15]保留", 0);
                writer.WriteBoolean("[bit14]协议版本标识", headerMessageBodyProperty.VersionFlag);
                writer.WriteBoolean("[bit13]是否分包", headerMessageBodyProperty.IsPackage);
                writer.WriteString("[bit10~bit12]数据加密", headerMessageBodyProperty.Encrypt.ToString());
                writer.WriteNumber("[bit0~bit9]消息体长度", headerMessageBodyProperty.DataLength);
                //消息体属性对象 结束
                writer.WriteEndObject();
                //2019版本
                var protocolVersion = reader.ReadByte();
                writer.WriteNumber($"[{protocolVersion.ReadNumber()}]协议版本号(2019)", protocolVersion);
                //  3.4.读取终端手机号
                var terminalPhoneNo = reader.ReadBCD(20, config.Trim);
                writer.WriteString($"[{terminalPhoneNo}]终端手机号", terminalPhoneNo);
            }
            else
            {
                reader.Version = JT808Version.JTT2013;
                writer.WriteNumber("[bit15]保留", 0);
                writer.WriteNumber("[bit14]保留", 0);
                writer.WriteBoolean("[bit13]是否分包", headerMessageBodyProperty.IsPackage);
                writer.WriteString("[bit10~bit12]数据加密", headerMessageBodyProperty.Encrypt.ToString());
                writer.WriteNumber("[bit0~bit9]消息体长度", headerMessageBodyProperty.DataLength);
                writer.WriteEndObject();
                //2013版本
                //  3.3.读取终端手机号
                var terminalPhoneNo = reader.ReadBCD(config.TerminalPhoneNoLength, false);
                //消息体属性对象 结束
                writer.WriteString($"[{terminalPhoneNo}]终端手机号", terminalPhoneNo);
            }
            //  3.4.读取消息流水号
            var msgNum = reader.ReadUInt16();

            writer.WriteNumber($"[{msgNum.ReadNumber()}]消息流水号", msgNum);
            //  3.5.判断有无分包
            uint packgeCount = 0, packageIndex = 0;

            if (headerMessageBodyProperty.IsPackage)
            {
                //3.5.1.读取消息包总数
                packgeCount = reader.ReadUInt16();
                writer.WriteNumber($"[{packgeCount.ReadNumber()}]消息包总数", packgeCount);
                //3.5.2.读取消息包序号
                packageIndex = reader.ReadUInt16();
                writer.WriteNumber($"[{packageIndex.ReadNumber()}]消息包序号", packageIndex);
            }
            // 4.处理数据体
            //  4.1.判断有无数据体
            if (headerMessageBodyProperty.DataLength > 0)
            {
                if (config.MsgIdFactory.TryGetValue(msgid, out object instance))
                {
                    //数据体属性对象 开始
                    writer.WriteStartObject("数据体对象");
                    string description = "数据体";
                    if (instance is IJT808Description jT808Description)
                    {
                        //4.2.处理消息体
                        description = jT808Description.Description;
                    }
                    if (headerMessageBodyProperty.IsPackage)
                    {
                        if (packageIndex > 1)
                        {
                            try
                            {
                                //4.2处理第二包之后的分包数据消息体
                                writer.WriteString($"[分包]数据体", reader.ReadContent().ToArray().ToHexString());
                            }
                            catch (Exception ex)
                            {
                                writer.WriteString($"[分包]数据体异常", ex.StackTrace);
                            }
                        }
                        else
                        {
                            try
                            {
                                //数据体长度正常
                                writer.WriteString($"[分包]{description}", reader.ReadVirtualArray(reader.ReadCurrentRemainContentLength()).ToArray().ToHexString());
                                if (instance is IJT808Analyze analyze)
                                {
                                    //4.2.处理消息体
                                    analyze.Analyze(ref reader, writer, config);
                                }
                            }
                            catch (IndexOutOfRangeException ex)
                            {
                                writer.WriteString($"数据体解析异常,无可用数据体进行解析", ex.StackTrace);
                            }
                            catch (ArgumentOutOfRangeException ex)
                            {
                                writer.WriteString($"[分包]数据体解析异常,无可用数据体进行解析", ex.StackTrace);
                            }
                            catch (Exception ex)
                            {
                                writer.WriteString($"[分包]数据体异常", ex.StackTrace);
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            //数据体长度正常
                            writer.WriteString($"{description}", reader.ReadVirtualArray(reader.ReadCurrentRemainContentLength()).ToArray().ToHexString());
                            if (instance is IJT808Analyze analyze)
                            {
                                //4.2.处理消息体
                                analyze.Analyze(ref reader, writer, config);
                            }
                        }
                        catch (IndexOutOfRangeException ex)
                        {
                            writer.WriteString($"数据体解析异常,无可用数据体进行解析", ex.StackTrace);
                        }
                        catch (ArgumentOutOfRangeException ex)
                        {
                            writer.WriteString($"数据体解析异常,无可用数据体进行解析", ex.StackTrace);
                        }
                        catch (Exception ex)
                        {
                            writer.WriteString($"数据体异常", ex.StackTrace);
                        }
                    }
                    //数据体属性对象 结束
                    writer.WriteEndObject();
                }
                else
                {
                    writer.WriteNull($"[Null]数据体");
                }
            }
            else
            {
                if (config.MsgIdFactory.TryGetValue(msgid, out object instance))
                {
                    //数据体属性对象 开始
                    writer.WriteStartObject("数据体对象");
                    string description = "[Null]数据体";
                    if (instance is IJT808Description jT808Description)
                    {
                        //4.2.处理消息体
                        description = jT808Description.Description;
                    }
                    writer.WriteNull(description);
                    //数据体属性对象 结束
                    writer.WriteEndObject();
                }
                else
                {
                    writer.WriteNull($"[Null]数据体");
                }
            }
            try
            {
                // 5.读取校验码
                reader.ReadByte();
                writer.WriteNumber($"[{reader.RealCheckXorCode.ReadNumber()}]校验码", reader.RealCheckXorCode);
                // 6.读取终止位置
                byte end = reader.ReadEnd();
                writer.WriteNumber($"[{end.ReadNumber()}]结束", end);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                writer.WriteString($"数据解析异常,无可用数据进行解析", ex.StackTrace);
            }
            catch (Exception ex)
            {
                writer.WriteString($"数据解析异常", ex.StackTrace);
            }
            finally
            {
                writer.WriteEndObject();
            }
        }
        /// <summary>
        /// Write to the JSON writer. Used during serialization with a requests associated converter.
        /// <param name="writer">Utf8JsonWriter</param>
        /// <param name="options">JsonSerializerOptions</param>
        /// </summary>
        override public void Write(Utf8JsonWriter writer, JsonSerializerOptions options)
        {
            base.Write(writer, options);

            if (CustomerId.HasValue)
            {
                writer.WriteNumber("Customer_ID", CustomerId.Value);
            }
            else if (CustomerLogin != null && CustomerLogin.Length > 0)
            {
                writer.WriteString("Customer_Login", CustomerLogin);
            }

            if (Description != null && Description.Length > 0)
            {
                writer.WriteString("Description", Description);
            }

            if (FirstName != null && FirstName.Length > 0)
            {
                writer.WriteString("FirstName", FirstName);
            }

            if (LastName != null && LastName.Length > 0)
            {
                writer.WriteString("LastName", LastName);
            }

            if (Email != null && Email.Length > 0)
            {
                writer.WriteString("Email", Email);
            }

            if (Phone != null && Phone.Length > 0)
            {
                writer.WriteString("Phone", Phone);
            }

            if (Fax != null && Fax.Length > 0)
            {
                writer.WriteString("Fax", Fax);
            }

            if (Company != null && Company.Length > 0)
            {
                writer.WriteString("Company", Company);
            }

            if (Address1 != null && Address1.Length > 0)
            {
                writer.WriteString("Address1", Address1);
            }

            if (Address2 != null && Address2.Length > 0)
            {
                writer.WriteString("Address2", Address2);
            }

            if (City != null && City.Length > 0)
            {
                writer.WriteString("City", City);
            }

            if (State != null && State.Length > 0)
            {
                writer.WriteString("State", State);
            }

            if (Zip != null && Zip.Length > 0)
            {
                writer.WriteString("Zip", Zip);
            }

            if (Country != null && Country.Length > 0)
            {
                writer.WriteString("Country", Country);
            }

            if (Residential.HasValue)
            {
                writer.WriteBoolean("Residential", Residential.Value);
            }
        }
        /// <summary>
        /// Serialize a FHIR QuestionnaireResponse#Answer into JSON
        /// </summary>
        public static void SerializeJson(this QuestionnaireResponse.AnswerComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            // Component: QuestionnaireResponse#Answer, Export: AnswerComponent, Base: BackboneElement (BackboneElement)
            ((Hl7.Fhir.Model.BackboneElement)current).SerializeJson(writer, options, false);

            if (current.Value != null)
            {
                switch (current.Value)
                {
                case FhirBoolean v_FhirBoolean:
                    if (v_FhirBoolean != null)
                    {
                        if (v_FhirBoolean.Value != null)
                        {
                            writer.WriteBoolean("valueBoolean", (bool)v_FhirBoolean.Value);
                        }
                        if (v_FhirBoolean.HasExtensions() || (!string.IsNullOrEmpty(v_FhirBoolean.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueBoolean", false, v_FhirBoolean.Extension, v_FhirBoolean.ElementId);
                        }
                    }
                    break;

                case FhirDecimal v_FhirDecimal:
                    if (v_FhirDecimal != null)
                    {
                        if (v_FhirDecimal.Value != null)
                        {
                            writer.WriteNumber("valueDecimal", (decimal)v_FhirDecimal.Value);
                        }
                        if (v_FhirDecimal.HasExtensions() || (!string.IsNullOrEmpty(v_FhirDecimal.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueDecimal", false, v_FhirDecimal.Extension, v_FhirDecimal.ElementId);
                        }
                    }
                    break;

                case Integer v_Integer:
                    if (v_Integer != null)
                    {
                        if (v_Integer.Value != null)
                        {
                            writer.WriteNumber("valueInteger", (int)v_Integer.Value);
                        }
                        if (v_Integer.HasExtensions() || (!string.IsNullOrEmpty(v_Integer.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueInteger", false, v_Integer.Extension, v_Integer.ElementId);
                        }
                    }
                    break;

                case Date v_Date:
                    if (v_Date != null)
                    {
                        if (!string.IsNullOrEmpty(v_Date.Value))
                        {
                            writer.WriteString("valueDate", v_Date.Value);
                        }
                        if (v_Date.HasExtensions() || (!string.IsNullOrEmpty(v_Date.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueDate", false, v_Date.Extension, v_Date.ElementId);
                        }
                    }
                    break;

                case FhirDateTime v_FhirDateTime:
                    if (v_FhirDateTime != null)
                    {
                        if (!string.IsNullOrEmpty(v_FhirDateTime.Value))
                        {
                            writer.WriteString("valueDateTime", v_FhirDateTime.Value);
                        }
                        if (v_FhirDateTime.HasExtensions() || (!string.IsNullOrEmpty(v_FhirDateTime.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueDateTime", false, v_FhirDateTime.Extension, v_FhirDateTime.ElementId);
                        }
                    }
                    break;

                case Time v_Time:
                    writer.WritePropertyName("valueTime");
                    v_Time.SerializeJson(writer, options);
                    break;

                case FhirString v_FhirString:
                    if (v_FhirString != null)
                    {
                        if (!string.IsNullOrEmpty(v_FhirString.Value))
                        {
                            writer.WriteString("valueString", v_FhirString.Value);
                        }
                        if (v_FhirString.HasExtensions() || (!string.IsNullOrEmpty(v_FhirString.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueString", false, v_FhirString.Extension, v_FhirString.ElementId);
                        }
                    }
                    break;

                case FhirUri v_FhirUri:
                    if (v_FhirUri != null)
                    {
                        if (!string.IsNullOrEmpty(v_FhirUri.Value))
                        {
                            writer.WriteString("valueUri", v_FhirUri.Value);
                        }
                        if (v_FhirUri.HasExtensions() || (!string.IsNullOrEmpty(v_FhirUri.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_valueUri", false, v_FhirUri.Extension, v_FhirUri.ElementId);
                        }
                    }
                    break;

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

                case Coding v_Coding:
                    writer.WritePropertyName("valueCoding");
                    v_Coding.SerializeJson(writer, options);
                    break;

                case Quantity v_Quantity:
                    writer.WritePropertyName("valueQuantity");
                    v_Quantity.SerializeJson(writer, options);
                    break;

                case ResourceReference v_ResourceReference:
                    writer.WritePropertyName("valueReference");
                    v_ResourceReference.SerializeJson(writer, options);
                    break;
                }
            }
            if ((current.Item != null) && (current.Item.Count != 0))
            {
                writer.WritePropertyName("item");
                writer.WriteStartArray();
                foreach (QuestionnaireResponse.ItemComponent val in current.Item)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Beispiel #13
0
        public static void WriteItem(this Utf8JsonWriter writer, KeyValuePair <string, object> item)
        {
            var key = item.Key;

            switch (item.Value)
            {
            case bool boolValue:
                writer.WriteBoolean(key, boolValue);
                break;

            case byte byteValue:
                writer.WriteNumber(key, byteValue);
                break;

            case sbyte sbyteValue:
                writer.WriteNumber(key, sbyteValue);
                break;

            case char charValue:
                writer.WriteString(key, MemoryMarshal.CreateSpan(ref charValue, 1));
                break;

            case decimal decimalValue:
                writer.WriteNumber(key, decimalValue);
                break;

            case double doubleValue:
                writer.WriteNumber(key, doubleValue);
                break;

            case float floatValue:
                writer.WriteNumber(key, floatValue);
                break;

            case int intValue:
                writer.WriteNumber(key, intValue);
                break;

            case uint uintValue:
                writer.WriteNumber(key, uintValue);
                break;

            case long longValue:
                writer.WriteNumber(key, longValue);
                break;

            case ulong ulongValue:
                writer.WriteNumber(key, ulongValue);
                break;

            case short shortValue:
                writer.WriteNumber(key, shortValue);
                break;

            case ushort ushortValue:
                writer.WriteNumber(key, ushortValue);
                break;

            case null:
                writer.WriteNull(key);
                break;

            default:
                writer.WriteString(key, ToInvariantString(item.Value));
                break;
            }
        }
Beispiel #14
0
        public override void Write(Utf8JsonWriter writer, ValidationResults value, JsonSerializerOptions options)
        {
            writer.WriteStartObject();

            writer.WriteBoolean("valid", value.IsValid);

            writer.WritePropertyName("keywordLocation");
            JsonSerializer.Serialize(writer, value.SchemaLocation);

            if (value.AbsoluteSchemaLocation != null)
            {
                writer.WritePropertyName("absoluteKeywordLocation");
                JsonSerializer.Serialize(writer, value.AbsoluteSchemaLocation);
            }

            writer.WritePropertyName("instanceLocation");
            JsonSerializer.Serialize(writer, value.InstanceLocation);

            if (!value.IsValid)
            {
                if (value.Message != null)
                {
                    writer.WriteString("error", value.Message);
                }

                if (value.NestedResults.Any())
                {
                    writer.WritePropertyName("errors");
                    JsonSerializer.Serialize(writer, value.NestedResults);
                }
            }
            else if (value.Annotations.Any(a => !a.WasConsolidated) || value.NestedResults.Any())
            {
                writer.WritePropertyName("annotations");
                writer.WriteStartArray();

                var annotations = value.Annotations.Where(a => !a.WasConsolidated).ToList();

                foreach (var result in value.NestedResults)
                {
                    var annotation = annotations.SingleOrDefault(a => a.Source.Equals(result.SchemaLocation));
                    if (annotation != null)
                    {
                        annotations.Remove(annotation);

                        WriteAnnotation(writer, value, annotation);
                    }
                    else
                    {
                        JsonSerializer.Serialize(writer, result);
                    }
                }

                foreach (var annotation in annotations)
                {
                    WriteAnnotation(writer, value, annotation);
                }

                writer.WriteEndArray();
            }

            writer.WriteEndObject();
        }
        /// <summary>
        /// Write to the JSON writer. Used during serialization with a requests associated converter.
        /// <param name="writer">Utf8JsonWriter</param>
        /// <param name="options">JsonSerializerOptions</param>
        /// </summary>
        override public void Write(Utf8JsonWriter writer, JsonSerializerOptions options)
        {
            base.Write(writer, options);

            if (ProductId.HasValue)
            {
                writer.WriteNumber("Product_ID", ProductId.Value);
            }
            else if (EditProduct != null && EditProduct.Length > 0)
            {
                writer.WriteString("Edit_Product", EditProduct);
            }
            else if (ProductCode != null && ProductCode.Length > 0)
            {
                writer.WriteString("Product_Code", ProductCode);
            }

            if (AttributeId.HasValue)
            {
                writer.WriteNumber("Attribute_ID", AttributeId.Value);
            }
            else if (EditAttribute != null && EditAttribute.Length > 0)
            {
                writer.WriteString("Edit_Attribute", EditAttribute);
            }
            else if (AttributeCode != null && AttributeCode.Length > 0)
            {
                writer.WriteString("Attribute_Code", AttributeCode);
            }

            if (OptionId.HasValue)
            {
                writer.WriteNumber("Option_ID", OptionId.Value);
            }
            else if (OptionCode != null && OptionCode.Length > 0)
            {
                writer.WriteString("Option_Code", OptionCode);
            }

            if (Code != null && Code.Length > 0)
            {
                writer.WriteString("Code", Code);
            }

            if (Prompt != null && Prompt.Length > 0)
            {
                writer.WriteString("Prompt", Prompt);
            }

            if (Image != null && Image.Length > 0)
            {
                writer.WriteString("Image", Image);
            }

            if (Price.HasValue)
            {
                writer.WriteNumber("Price", Price.Value);
            }

            if (Cost.HasValue)
            {
                writer.WriteNumber("Cost", Cost.Value);
            }

            if (Weight.HasValue)
            {
                writer.WriteNumber("Weight", Weight.Value);
            }

            if (Default.HasValue)
            {
                writer.WriteBoolean("Default", Default.Value);
            }
        }
Beispiel #16
0
 void IJsonSerializable.WriteToJson(Utf8JsonWriter writer, WritedObjects objrefs)
 {
     writer.WriteBoolean("Route", (Flag & ViewModelFlag.ListInRouter) == ViewModelFlag.ListInRouter);
     writer.WriteString("RouteParent", RouteParent);
     writer.WriteString("RoutePath", RoutePath);
 }
 public void Write(Span <byte> escapedPropertyName, bool?value, ref Utf8JsonWriter writer)
 {
     writer.WriteBoolean(escapedPropertyName, value.Value);
 }
Beispiel #18
0
        /// <summary>
        /// Serialize a FHIR CompartmentDefinition into JSON
        /// </summary>
        public static void SerializeJson(this CompartmentDefinition current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            writer.WriteString("resourceType", "CompartmentDefinition");
            // Complex: CompartmentDefinition, Export: CompartmentDefinition, Base: DomainResource (DomainResource)
            ((Hl7.Fhir.Model.DomainResource)current).SerializeJson(writer, options, false);

            writer.WriteString("url", current.UrlElement.Value);

            if (current.VersionElement != null)
            {
                if (!string.IsNullOrEmpty(current.VersionElement.Value))
                {
                    writer.WriteString("version", current.VersionElement.Value);
                }
                if (current.VersionElement.HasExtensions() || (!string.IsNullOrEmpty(current.VersionElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_version", false, current.VersionElement.Extension, current.VersionElement.ElementId);
                }
            }

            writer.WriteString("name", current.NameElement.Value);

            writer.WriteString("status", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.StatusElement.Value));

            if (current.ExperimentalElement != null)
            {
                if (current.ExperimentalElement.Value != null)
                {
                    writer.WriteBoolean("experimental", (bool)current.ExperimentalElement.Value);
                }
                if (current.ExperimentalElement.HasExtensions() || (!string.IsNullOrEmpty(current.ExperimentalElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_experimental", false, current.ExperimentalElement.Extension, current.ExperimentalElement.ElementId);
                }
            }

            if (current.DateElement != null)
            {
                if (!string.IsNullOrEmpty(current.DateElement.Value))
                {
                    writer.WriteString("date", current.DateElement.Value);
                }
                if (current.DateElement.HasExtensions() || (!string.IsNullOrEmpty(current.DateElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_date", false, current.DateElement.Extension, current.DateElement.ElementId);
                }
            }

            if (current.PublisherElement != null)
            {
                if (!string.IsNullOrEmpty(current.PublisherElement.Value))
                {
                    writer.WriteString("publisher", current.PublisherElement.Value);
                }
                if (current.PublisherElement.HasExtensions() || (!string.IsNullOrEmpty(current.PublisherElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_publisher", false, current.PublisherElement.Extension, current.PublisherElement.ElementId);
                }
            }

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

            if (current.Description != null)
            {
                if (!string.IsNullOrEmpty(current.Description.Value))
                {
                    writer.WriteString("description", current.Description.Value);
                }
                if (current.Description.HasExtensions() || (!string.IsNullOrEmpty(current.Description.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_description", false, current.Description.Extension, current.Description.ElementId);
                }
            }

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

            if (current.Purpose != null)
            {
                if (!string.IsNullOrEmpty(current.Purpose.Value))
                {
                    writer.WriteString("purpose", current.Purpose.Value);
                }
                if (current.Purpose.HasExtensions() || (!string.IsNullOrEmpty(current.Purpose.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_purpose", false, current.Purpose.Extension, current.Purpose.ElementId);
                }
            }

            writer.WriteString("code", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.CodeElement.Value));

            writer.WriteBoolean("search", (bool)current.SearchElement.Value);

            if ((current.Resource != null) && (current.Resource.Count != 0))
            {
                writer.WritePropertyName("resource");
                writer.WriteStartArray();
                foreach (CompartmentDefinition.ResourceComponent val in current.Resource)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
        public override void Write(Utf8JsonWriter writer, DateTimeFormatOptions value, JsonSerializerOptions options)
        {
            if (value is not null)
            {
                writer.WriteStartObject();
                var localeMatcher = value.LocaleMatcher.ToString();
                if (!string.IsNullOrWhiteSpace(localeMatcher))
                {
                    writer.WriteString("localeMatcher", localeMatcher);
                }

                var weekday = value.Weekday.ToString();
                if (!string.IsNullOrWhiteSpace(weekday))
                {
                    writer.WriteString("weekday", weekday);
                }

                var era = value.Era.ToString();
                if (!string.IsNullOrWhiteSpace(era))
                {
                    writer.WriteString("era", era);
                }

                var year = value.Year.ToString();
                if (!string.IsNullOrWhiteSpace(year))
                {
                    writer.WriteString("year", year);
                }

                var month = value.Month.ToString();
                if (!string.IsNullOrWhiteSpace(month))
                {
                    writer.WriteString("month", month);
                }

                var day = value.Day.ToString();
                if (!string.IsNullOrWhiteSpace(day))
                {
                    writer.WriteString("day", day);
                }

                var hour = value.Hour.ToString();
                if (!string.IsNullOrWhiteSpace(hour))
                {
                    writer.WriteString("hour", hour);
                }

                var minute = value.Minute.ToString();
                if (!string.IsNullOrWhiteSpace(minute))
                {
                    writer.WriteString("minute", minute);
                }

                var second = value.Second.ToString();
                if (!string.IsNullOrWhiteSpace(second))
                {
                    writer.WriteString("second", second);
                }

                var timeZoneName = value.TimeZoneName.ToString();
                if (!string.IsNullOrWhiteSpace(timeZoneName))
                {
                    writer.WriteString("timeZoneName", timeZoneName);
                }

                var formatMatcher = value.FormatMatcher.ToString();
                if (!string.IsNullOrWhiteSpace(formatMatcher))
                {
                    writer.WriteString("formatMatcher", formatMatcher);
                }

                if (value.Hour12.HasValue)
                {
                    writer.WriteBoolean("hour12", value.Hour12.Value);
                }

                if (value.TimeZone is not null)
                {
                    writer.WriteString("timeZone", value.TimeZone);
                }

                writer.WriteEndObject();
            }
        }
Beispiel #20
0
        /// <summary>
        /// Serialize to a JSON object
        /// </summary>
        public new void SerializeJson(Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            if (!string.IsNullOrEmpty(ResourceType))
            {
                writer.WriteString("resourceType", (string)ResourceType !);
            }


            ((fhirCsR4.Models.DomainResource) this).SerializeJson(writer, options, false);

            if ((Identifier != null) && (Identifier.Count != 0))
            {
                writer.WritePropertyName("identifier");
                writer.WriteStartArray();

                foreach (Identifier valIdentifier in Identifier)
                {
                    valIdentifier.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (Active != null)
            {
                writer.WriteBoolean("active", (bool)Active !);
            }

            if ((ServiceCategory != null) && (ServiceCategory.Count != 0))
            {
                writer.WritePropertyName("serviceCategory");
                writer.WriteStartArray();

                foreach (CodeableConcept valServiceCategory in ServiceCategory)
                {
                    valServiceCategory.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((ServiceType != null) && (ServiceType.Count != 0))
            {
                writer.WritePropertyName("serviceType");
                writer.WriteStartArray();

                foreach (CodeableConcept valServiceType in ServiceType)
                {
                    valServiceType.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Specialty != null) && (Specialty.Count != 0))
            {
                writer.WritePropertyName("specialty");
                writer.WriteStartArray();

                foreach (CodeableConcept valSpecialty in Specialty)
                {
                    valSpecialty.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Actor != null) && (Actor.Count != 0))
            {
                writer.WritePropertyName("actor");
                writer.WriteStartArray();

                foreach (Reference valActor in Actor)
                {
                    valActor.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (PlanningHorizon != null)
            {
                writer.WritePropertyName("planningHorizon");
                PlanningHorizon.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Comment))
            {
                writer.WriteString("comment", (string)Comment !);
            }

            if (_Comment != null)
            {
                writer.WritePropertyName("_comment");
                _Comment.SerializeJson(writer, options);
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Beispiel #21
0
        /// <summary>
        /// Serialize a FHIR BodyStructure into JSON
        /// </summary>
        public static void SerializeJson(this BodyStructure current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            writer.WriteString("resourceType", "BodyStructure");
            // Complex: BodyStructure, Export: BodyStructure, Base: DomainResource (DomainResource)
            ((Hl7.Fhir.Model.DomainResource)current).SerializeJson(writer, options, false);

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

            if (current.ActiveElement != null)
            {
                if (current.ActiveElement.Value != null)
                {
                    writer.WriteBoolean("active", (bool)current.ActiveElement.Value);
                }
                if (current.ActiveElement.HasExtensions() || (!string.IsNullOrEmpty(current.ActiveElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_active", false, current.ActiveElement.Extension, current.ActiveElement.ElementId);
                }
            }

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

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

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

            if (current.DescriptionElement != null)
            {
                if (!string.IsNullOrEmpty(current.DescriptionElement.Value))
                {
                    writer.WriteString("description", current.DescriptionElement.Value);
                }
                if (current.DescriptionElement.HasExtensions() || (!string.IsNullOrEmpty(current.DescriptionElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_description", false, current.DescriptionElement.Extension, current.DescriptionElement.ElementId);
                }
            }

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

            writer.WritePropertyName("patient");
            current.Patient.SerializeJson(writer, options);

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
        /// <summary>
        /// Serialize to a JSON object
        /// </summary>
        public new void SerializeJson(Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }

            if (!string.IsNullOrEmpty(ResourceType))
            {
                writer.WriteString("resourceType", (string)ResourceType !);
            }


            ((Fhir.R4.Models.DomainResource) this).SerializeJson(writer, options, false);

            if ((Identifier != null) && (Identifier.Count != 0))
            {
                writer.WritePropertyName("identifier");
                writer.WriteStartArray();

                foreach (Identifier valIdentifier in Identifier)
                {
                    valIdentifier.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((InstantiatesCanonical != null) && (InstantiatesCanonical.Count != 0))
            {
                writer.WritePropertyName("instantiatesCanonical");
                writer.WriteStartArray();

                foreach (string valInstantiatesCanonical in InstantiatesCanonical)
                {
                    writer.WriteStringValue(valInstantiatesCanonical);
                }

                writer.WriteEndArray();
            }

            if ((_InstantiatesCanonical != null) && (_InstantiatesCanonical.Count != 0))
            {
                writer.WritePropertyName("_instantiatesCanonical");
                writer.WriteStartArray();

                foreach (Element val_InstantiatesCanonical in _InstantiatesCanonical)
                {
                    val_InstantiatesCanonical.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((InstantiatesUri != null) && (InstantiatesUri.Count != 0))
            {
                writer.WritePropertyName("instantiatesUri");
                writer.WriteStartArray();

                foreach (string valInstantiatesUri in InstantiatesUri)
                {
                    writer.WriteStringValue(valInstantiatesUri);
                }

                writer.WriteEndArray();
            }

            if ((_InstantiatesUri != null) && (_InstantiatesUri.Count != 0))
            {
                writer.WritePropertyName("_instantiatesUri");
                writer.WriteStartArray();

                foreach (Element val_InstantiatesUri in _InstantiatesUri)
                {
                    val_InstantiatesUri.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (!string.IsNullOrEmpty(Status))
            {
                writer.WriteString("status", (string)Status !);
            }

            if (_Status != null)
            {
                writer.WritePropertyName("_status");
                _Status.SerializeJson(writer, options);
            }

            if (DataAbsentReason != null)
            {
                writer.WritePropertyName("dataAbsentReason");
                DataAbsentReason.SerializeJson(writer, options);
            }

            if (Patient != null)
            {
                writer.WritePropertyName("patient");
                Patient.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Date))
            {
                writer.WriteString("date", (string)Date !);
            }

            if (_Date != null)
            {
                writer.WritePropertyName("_date");
                _Date.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Name))
            {
                writer.WriteString("name", (string)Name !);
            }

            if (_Name != null)
            {
                writer.WritePropertyName("_name");
                _Name.SerializeJson(writer, options);
            }

            if (Relationship != null)
            {
                writer.WritePropertyName("relationship");
                Relationship.SerializeJson(writer, options);
            }

            if (Sex != null)
            {
                writer.WritePropertyName("sex");
                Sex.SerializeJson(writer, options);
            }

            if (BornPeriod != null)
            {
                writer.WritePropertyName("bornPeriod");
                BornPeriod.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(BornDate))
            {
                writer.WriteString("bornDate", (string)BornDate !);
            }

            if (_BornDate != null)
            {
                writer.WritePropertyName("_bornDate");
                _BornDate.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(BornString))
            {
                writer.WriteString("bornString", (string)BornString !);
            }

            if (_BornString != null)
            {
                writer.WritePropertyName("_bornString");
                _BornString.SerializeJson(writer, options);
            }

            if (AgeAge != null)
            {
                writer.WritePropertyName("ageAge");
                AgeAge.SerializeJson(writer, options);
            }

            if (AgeRange != null)
            {
                writer.WritePropertyName("ageRange");
                AgeRange.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(AgeString))
            {
                writer.WriteString("ageString", (string)AgeString !);
            }

            if (_AgeString != null)
            {
                writer.WritePropertyName("_ageString");
                _AgeString.SerializeJson(writer, options);
            }

            if (EstimatedAge != null)
            {
                writer.WriteBoolean("estimatedAge", (bool)EstimatedAge !);
            }

            if (DeceasedBoolean != null)
            {
                writer.WriteBoolean("deceasedBoolean", (bool)DeceasedBoolean !);
            }

            if (DeceasedAge != null)
            {
                writer.WritePropertyName("deceasedAge");
                DeceasedAge.SerializeJson(writer, options);
            }

            if (DeceasedRange != null)
            {
                writer.WritePropertyName("deceasedRange");
                DeceasedRange.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(DeceasedDate))
            {
                writer.WriteString("deceasedDate", (string)DeceasedDate !);
            }

            if (_DeceasedDate != null)
            {
                writer.WritePropertyName("_deceasedDate");
                _DeceasedDate.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(DeceasedString))
            {
                writer.WriteString("deceasedString", (string)DeceasedString !);
            }

            if (_DeceasedString != null)
            {
                writer.WritePropertyName("_deceasedString");
                _DeceasedString.SerializeJson(writer, options);
            }

            if ((ReasonCode != null) && (ReasonCode.Count != 0))
            {
                writer.WritePropertyName("reasonCode");
                writer.WriteStartArray();

                foreach (CodeableConcept valReasonCode in ReasonCode)
                {
                    valReasonCode.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((ReasonReference != null) && (ReasonReference.Count != 0))
            {
                writer.WritePropertyName("reasonReference");
                writer.WriteStartArray();

                foreach (Reference valReasonReference in ReasonReference)
                {
                    valReasonReference.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Note != null) && (Note.Count != 0))
            {
                writer.WritePropertyName("note");
                writer.WriteStartArray();

                foreach (Annotation valNote in Note)
                {
                    valNote.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Condition != null) && (Condition.Count != 0))
            {
                writer.WritePropertyName("condition");
                writer.WriteStartArray();

                foreach (FamilyMemberHistoryCondition valCondition in Condition)
                {
                    valCondition.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Beispiel #23
0
        /// <summary>
        /// Serialize to a JSON object
        /// </summary>
        public new void SerializeJson(Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            ((fhirCsR4.Models.Element) this).SerializeJson(writer, options, false);

            if (!string.IsNullOrEmpty(System))
            {
                writer.WriteString("system", (string)System !);
            }

            if (_System != null)
            {
                writer.WritePropertyName("_system");
                _System.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Version))
            {
                writer.WriteString("version", (string)Version !);
            }

            if (_Version != null)
            {
                writer.WritePropertyName("_version");
                _Version.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Code))
            {
                writer.WriteString("code", (string)Code !);
            }

            if (_Code != null)
            {
                writer.WritePropertyName("_code");
                _Code.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Display))
            {
                writer.WriteString("display", (string)Display !);
            }

            if (_Display != null)
            {
                writer.WritePropertyName("_display");
                _Display.SerializeJson(writer, options);
            }

            if (UserSelected != null)
            {
                writer.WriteBoolean("userSelected", (bool)UserSelected !);
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
        /// <summary>
        /// Serialize to a JSON object
        /// </summary>
        public new void SerializeJson(Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }

            ((Fhir.R4.Models.BackboneElement) this).SerializeJson(writer, options, false);

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

            if (Outcome != null)
            {
                writer.WritePropertyName("outcome");
                Outcome.SerializeJson(writer, options);
            }

            if (ContributedToDeath != null)
            {
                writer.WriteBoolean("contributedToDeath", (bool)ContributedToDeath !);
            }

            if (OnsetAge != null)
            {
                writer.WritePropertyName("onsetAge");
                OnsetAge.SerializeJson(writer, options);
            }

            if (OnsetRange != null)
            {
                writer.WritePropertyName("onsetRange");
                OnsetRange.SerializeJson(writer, options);
            }

            if (OnsetPeriod != null)
            {
                writer.WritePropertyName("onsetPeriod");
                OnsetPeriod.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(OnsetString))
            {
                writer.WriteString("onsetString", (string)OnsetString !);
            }

            if (_OnsetString != null)
            {
                writer.WritePropertyName("_onsetString");
                _OnsetString.SerializeJson(writer, options);
            }

            if ((Note != null) && (Note.Count != 0))
            {
                writer.WritePropertyName("note");
                writer.WriteStartArray();

                foreach (Annotation valNote in Note)
                {
                    valNote.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Beispiel #25
0
        /// <summary>
        /// Serialize to a JSON object
        /// </summary>
        public new void SerializeJson(Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            if (!string.IsNullOrEmpty(ResourceType))
            {
                writer.WriteString("resourceType", (string)ResourceType !);
            }


            ((fhirCsR4.Models.DomainResource) this).SerializeJson(writer, options, false);

            if ((Identifier != null) && (Identifier.Count != 0))
            {
                writer.WritePropertyName("identifier");
                writer.WriteStartArray();

                foreach (Identifier valIdentifier in Identifier)
                {
                    valIdentifier.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (Active != null)
            {
                writer.WriteBoolean("active", (bool)Active !);
            }

            if ((Name != null) && (Name.Count != 0))
            {
                writer.WritePropertyName("name");
                writer.WriteStartArray();

                foreach (HumanName valName in Name)
                {
                    valName.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Telecom != null) && (Telecom.Count != 0))
            {
                writer.WritePropertyName("telecom");
                writer.WriteStartArray();

                foreach (ContactPoint valTelecom in Telecom)
                {
                    valTelecom.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Address != null) && (Address.Count != 0))
            {
                writer.WritePropertyName("address");
                writer.WriteStartArray();

                foreach (Address valAddress in Address)
                {
                    valAddress.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (!string.IsNullOrEmpty(Gender))
            {
                writer.WriteString("gender", (string)Gender !);
            }

            if (_Gender != null)
            {
                writer.WritePropertyName("_gender");
                _Gender.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(BirthDate))
            {
                writer.WriteString("birthDate", (string)BirthDate !);
            }

            if (_BirthDate != null)
            {
                writer.WritePropertyName("_birthDate");
                _BirthDate.SerializeJson(writer, options);
            }

            if ((Photo != null) && (Photo.Count != 0))
            {
                writer.WritePropertyName("photo");
                writer.WriteStartArray();

                foreach (Attachment valPhoto in Photo)
                {
                    valPhoto.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Qualification != null) && (Qualification.Count != 0))
            {
                writer.WritePropertyName("qualification");
                writer.WriteStartArray();

                foreach (PractitionerQualification valQualification in Qualification)
                {
                    valQualification.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Communication != null) && (Communication.Count != 0))
            {
                writer.WritePropertyName("communication");
                writer.WriteStartArray();

                foreach (CodeableConcept valCommunication in Communication)
                {
                    valCommunication.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
        public override async Task WriteMessageAsync(Message message)
        {
            _writer.WriteStartObject();

            // Metadata
            _writer.WriteString("id", message.Id);
            _writer.WriteString("type", message.Type.ToString());
            _writer.WriteString("timestamp", message.Timestamp);
            _writer.WriteString("timestampEdited", message.EditedTimestamp);
            _writer.WriteBoolean("isPinned", message.IsPinned);

            // Content
            var content = PlainTextRenderingLogic.FormatMessageContent(Context, message);

            _writer.WriteString("content", content);

            // Author
            _writer.WriteStartObject("author");
            _writer.WriteString("id", message.Author.Id);
            _writer.WriteString("name", message.Author.Name);
            _writer.WriteString("discriminator", $"{message.Author.Discriminator:0000}");
            _writer.WriteBoolean("isBot", message.Author.IsBot);
            _writer.WriteString("avatarUrl", message.Author.AvatarUrl);
            _writer.WriteEndObject();

            // Attachments
            _writer.WriteStartArray("attachments");

            foreach (var attachment in message.Attachments)
            {
                _writer.WriteStartObject();

                _writer.WriteString("id", attachment.Id);
                _writer.WriteString("url", attachment.Url);
                _writer.WriteString("fileName", attachment.FileName);
                _writer.WriteNumber("fileSizeBytes", (long)attachment.FileSize.Bytes);

                _writer.WriteEndObject();
            }

            _writer.WriteEndArray();

            // Embeds
            _writer.WriteStartArray("embeds");

            foreach (var embed in message.Embeds)
            {
                _writer.WriteStartObject();

                _writer.WriteString("title", embed.Title);
                _writer.WriteString("url", embed.Url);
                _writer.WriteString("timestamp", embed.Timestamp);
                _writer.WriteString("description", embed.Description);

                // Author
                if (embed.Author != null)
                {
                    _writer.WriteStartObject("author");
                    _writer.WriteString("name", embed.Author.Name);
                    _writer.WriteString("url", embed.Author.Url);
                    _writer.WriteString("iconUrl", embed.Author.IconUrl);
                    _writer.WriteEndObject();
                }

                // Thumbnail
                if (embed.Thumbnail != null)
                {
                    _writer.WriteStartObject("thumbnail");
                    _writer.WriteString("url", embed.Thumbnail.Url);
                    _writer.WriteNumber("width", embed.Thumbnail.Width);
                    _writer.WriteNumber("height", embed.Thumbnail.Height);
                    _writer.WriteEndObject();
                }

                // Image
                if (embed.Image != null)
                {
                    _writer.WriteStartObject("image");
                    _writer.WriteString("url", embed.Image.Url);
                    _writer.WriteNumber("width", embed.Image.Width);
                    _writer.WriteNumber("height", embed.Image.Height);
                    _writer.WriteEndObject();
                }

                // Footer
                if (embed.Footer != null)
                {
                    _writer.WriteStartObject("footer");
                    _writer.WriteString("text", embed.Footer.Text);
                    _writer.WriteString("iconUrl", embed.Footer.IconUrl);
                    _writer.WriteEndObject();
                }

                // Fields
                _writer.WriteStartArray("fields");

                foreach (var field in embed.Fields)
                {
                    _writer.WriteStartObject();

                    _writer.WriteString("name", field.Name);
                    _writer.WriteString("value", field.Value);
                    _writer.WriteBoolean("isInline", field.IsInline);

                    _writer.WriteEndObject();
                }

                _writer.WriteEndArray();

                _writer.WriteEndObject();
            }

            _writer.WriteEndArray();

            // Reactions
            _writer.WriteStartArray("reactions");

            foreach (var reaction in message.Reactions)
            {
                _writer.WriteStartObject();

                // Emoji
                _writer.WriteStartObject("emoji");
                _writer.WriteString("id", reaction.Emoji.Id);
                _writer.WriteString("name", reaction.Emoji.Name);
                _writer.WriteBoolean("isAnimated", reaction.Emoji.IsAnimated);
                _writer.WriteString("imageUrl", reaction.Emoji.ImageUrl);
                _writer.WriteEndObject();

                // Count
                _writer.WriteNumber("count", reaction.Count);

                _writer.WriteEndObject();
            }

            _writer.WriteEndArray();

            _writer.WriteEndObject();

            _messageCount++;

            // Flush every 100 messages
            if (_messageCount % 100 == 0)
            {
                await _writer.FlushAsync();
            }
        }
Beispiel #27
0
        /// <summary>
        /// Serialize to a JSON object
        /// </summary>
        public new void SerializeJson(Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }

            if (!string.IsNullOrEmpty(ResourceType))
            {
                writer.WriteString("resourceType", (string)ResourceType !);
            }


            ((Fhir.R4.Models.DomainResource) this).SerializeJson(writer, options, false);

            if (!string.IsNullOrEmpty(Url))
            {
                writer.WriteString("url", (string)Url !);
            }

            if (_Url != null)
            {
                writer.WritePropertyName("_url");
                _Url.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Version))
            {
                writer.WriteString("version", (string)Version !);
            }

            if (_Version != null)
            {
                writer.WritePropertyName("_version");
                _Version.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Name))
            {
                writer.WriteString("name", (string)Name !);
            }

            if (_Name != null)
            {
                writer.WritePropertyName("_name");
                _Name.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Status))
            {
                writer.WriteString("status", (string)Status !);
            }

            if (_Status != null)
            {
                writer.WritePropertyName("_status");
                _Status.SerializeJson(writer, options);
            }

            if (Experimental != null)
            {
                writer.WriteBoolean("experimental", (bool)Experimental !);
            }

            if (!string.IsNullOrEmpty(Date))
            {
                writer.WriteString("date", (string)Date !);
            }

            if (_Date != null)
            {
                writer.WritePropertyName("_date");
                _Date.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Publisher))
            {
                writer.WriteString("publisher", (string)Publisher !);
            }

            if (_Publisher != null)
            {
                writer.WritePropertyName("_publisher");
                _Publisher.SerializeJson(writer, options);
            }

            if ((Contact != null) && (Contact.Count != 0))
            {
                writer.WritePropertyName("contact");
                writer.WriteStartArray();

                foreach (ContactDetail valContact in Contact)
                {
                    valContact.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (!string.IsNullOrEmpty(Description))
            {
                writer.WriteString("description", (string)Description !);
            }

            if (_Description != null)
            {
                writer.WritePropertyName("_description");
                _Description.SerializeJson(writer, options);
            }

            if ((UseContext != null) && (UseContext.Count != 0))
            {
                writer.WritePropertyName("useContext");
                writer.WriteStartArray();

                foreach (UsageContext valUseContext in UseContext)
                {
                    valUseContext.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Jurisdiction != null) && (Jurisdiction.Count != 0))
            {
                writer.WritePropertyName("jurisdiction");
                writer.WriteStartArray();

                foreach (CodeableConcept valJurisdiction in Jurisdiction)
                {
                    valJurisdiction.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (!string.IsNullOrEmpty(Purpose))
            {
                writer.WriteString("purpose", (string)Purpose !);
            }

            if (_Purpose != null)
            {
                writer.WritePropertyName("_purpose");
                _Purpose.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Start))
            {
                writer.WriteString("start", (string)Start !);
            }

            if (_Start != null)
            {
                writer.WritePropertyName("_start");
                _Start.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Profile))
            {
                writer.WriteString("profile", (string)Profile !);
            }

            if (_Profile != null)
            {
                writer.WritePropertyName("_profile");
                _Profile.SerializeJson(writer, options);
            }

            if ((Link != null) && (Link.Count != 0))
            {
                writer.WritePropertyName("link");
                writer.WriteStartArray();

                foreach (GraphDefinitionLink valLink in Link)
                {
                    valLink.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
        /// <summary>
        /// Write to the JSON writer. Used during serialization with a requests associated converter.
        /// <param name="writer">Utf8JsonWriter</param>
        /// <param name="options">JsonSerializerOptions</param>
        /// </summary>
        override public void Write(Utf8JsonWriter writer, JsonSerializerOptions options)
        {
            base.Write(writer, options);

            if (AttributeTemplateId.HasValue)
            {
                writer.WriteNumber("AttributeTemplate_ID", AttributeTemplateId.Value);
            }
            else if (AttributeTemplateCode != null && AttributeTemplateCode.Length > 0)
            {
                writer.WriteString("AttributeTemplate_Code", AttributeTemplateCode);
            }
            else if (EditAttributeTemplate != null && EditAttributeTemplate.Length > 0)
            {
                writer.WriteString("Edit_AttributeTemplate", EditAttributeTemplate);
            }

            writer.WriteString("Code", Code);

            if (Prompt != null && Prompt.Length > 0)
            {
                writer.WriteString("Prompt", Prompt);
            }

            writer.WriteString("Type", AttributeType);

            if (Image != null && Image.Length > 0)
            {
                writer.WriteString("Image", Image);
            }

            if (Price.HasValue)
            {
                writer.WriteNumber("Price", Price.Value);
            }

            if (Cost.HasValue)
            {
                writer.WriteNumber("Cost", Cost.Value);
            }

            if (Weight.HasValue)
            {
                writer.WriteNumber("Weight", Weight.Value);
            }

            if (Copy.HasValue)
            {
                writer.WriteBoolean("Copy", Copy.Value);
            }

            if (Required.HasValue)
            {
                writer.WriteBoolean("Required", Required.Value);
            }

            if (Inventory.HasValue)
            {
                writer.WriteBoolean("Inventory", Inventory.Value);
            }
        }
Beispiel #29
0
        IObjectWriter IObjectWriter.WriteProperty(string property, bool value)
        {
            jsonWriter?.WriteBoolean(property, value);

            return(this);
        }
Beispiel #30
0
        /// <summary>
        /// Write to the JSON writer. Used during serialization with a requests associated converter.
        /// <param name="writer">Utf8JsonWriter</param>
        /// <param name="options">JsonSerializerOptions</param>
        /// </summary>
        override public void Write(Utf8JsonWriter writer, JsonSerializerOptions options)
        {
            base.Write(writer, options);

            if (PriceGroupId.HasValue)
            {
                writer.WriteNumber("PriceGroup_ID", PriceGroupId.Value);
            }
            else if (EditPriceGroup != null && EditPriceGroup.Length > 0)
            {
                writer.WriteString("Edit_PriceGroup", EditPriceGroup);
            }
            else if (PriceGroupName != null && PriceGroupName.Length > 0)
            {
                writer.WriteString("PriceGroup_Name", PriceGroupName);
            }

            writer.WriteString("PriceGroup_Name", PriceGroupName);

            if (Name != null && Name.Length > 0)
            {
                writer.WriteString("Name", Name);
            }

            if (CustomerScope != null && CustomerScope.Length > 0)
            {
                writer.WriteString("CustomerScope", CustomerScope);
            }

            if (Rate != null && Rate.Length > 0)
            {
                writer.WriteString("Rate", Rate);
            }

            if (Discount.HasValue)
            {
                writer.WriteNumber("Discount", Discount.Value);
            }

            if (Markup.HasValue)
            {
                writer.WriteNumber("Markup", Markup.Value);
            }

            if (ModuleId.HasValue)
            {
                writer.WriteNumber("Module_ID", ModuleId.Value);
            }

            if (Exclusion.HasValue)
            {
                writer.WriteBoolean("Exclusion", Exclusion.Value);
            }

            if (Description != null && Description.Length > 0)
            {
                writer.WriteString("Description", Description);
            }

            if (Display.HasValue)
            {
                writer.WriteBoolean("Display", Display.Value);
            }

            if (DateTimeStart.HasValue)
            {
                writer.WriteNumber("DateTime_Start", new DateTimeOffset(DateTimeStart.Value).ToUnixTimeSeconds());
            }

            if (DateTimeEnd.HasValue)
            {
                writer.WriteNumber("DateTime_End", new DateTimeOffset(DateTimeEnd.Value).ToUnixTimeSeconds());
            }

            if (QualifyingMinSubtotal.HasValue)
            {
                writer.WriteNumber("Qualifying_Min_Subtotal", QualifyingMinSubtotal.Value);
            }

            if (QualifyingMaxSubtotal.HasValue)
            {
                writer.WriteNumber("Qualifying_Max_Subtotal", QualifyingMaxSubtotal.Value);
            }

            if (QualifyingMinQuantity.HasValue)
            {
                writer.WriteNumber("Qualifying_Min_Quantity", QualifyingMinQuantity.Value);
            }

            if (QualifyingMaxQuantity.HasValue)
            {
                writer.WriteNumber("Qualifying_Max_Quantity", QualifyingMaxQuantity.Value);
            }

            if (QualifyingMinWeight.HasValue)
            {
                writer.WriteNumber("Qualifying_Min_Weight", QualifyingMinWeight.Value);
            }

            if (QualifyingMaxWeight.HasValue)
            {
                writer.WriteNumber("Qualifying_Max_Weight", QualifyingMaxWeight.Value);
            }

            if (BasketMinSubtotal.HasValue)
            {
                writer.WriteNumber("Basket_Min_Subtotal", BasketMinSubtotal.Value);
            }

            if (BasketMaxSubtotal.HasValue)
            {
                writer.WriteNumber("Basket_Max_Subtotal", BasketMaxSubtotal.Value);
            }

            if (BasketMinQuantity.HasValue)
            {
                writer.WriteNumber("Basket_Min_Quantity", BasketMinQuantity.Value);
            }

            if (BasketMaxQuantity.HasValue)
            {
                writer.WriteNumber("Basket_Max_Quantity", BasketMaxQuantity.Value);
            }

            if (BasketMinWeight.HasValue)
            {
                writer.WriteNumber("Basket_Min_Weight", BasketMinWeight.Value);
            }

            if (BasketMaxWeight.HasValue)
            {
                writer.WriteNumber("Basket_Max_Weight", BasketMaxWeight.Value);
            }

            if (Priority.HasValue)
            {
                writer.WriteNumber("Priority", Priority.Value);
            }

            if (Exclusions.Count > 0)
            {
                writer.WritePropertyName("Exclusions");
                JsonSerializer.Serialize(writer, this.Exclusions, options);
            }

            if (ModuleFields.Count > 0)
            {
                foreach (KeyValuePair <String, IConvertible> entry in ModuleFields)
                {
                    if (Util.IsDecimal(entry.Value))
                    {
                        if (Util.IsFloat(entry.Value))
                        {
                            writer.WriteNumber(entry.Key, (float)entry.Value);
                        }
                        else
                        {
                            writer.WriteNumber(entry.Key, (double)entry.Value);
                        }
                    }
                    else if (Util.IsNumeric(entry.Value))
                    {
                        writer.WriteNumber(entry.Key, (int)entry.Value);
                    }
                    else if (Util.IsBoolean(entry.Value))
                    {
                        writer.WriteBoolean(entry.Key, (bool)entry.Value);
                    }
                    else
                    {
                        writer.WriteString(entry.Key, entry.Value.ToString());
                    }
                }
            }
        }