bool MetricsEvent::SerializeToJson()

in Gems/AWSMetrics/Code/Source/MetricsEvent.cpp [70:104]


    bool MetricsEvent::SerializeToJson(AWSCore::JsonWriter& writer) const
    {
        bool ok = true;
        ok = ok && writer.StartObject();

        AZStd::vector<MetricsAttribute> customAttributes;
        for (const auto& attr : m_attributes)
        {
            if (attr.IsDefault())
            {
                ok = ok && writer.Key(attr.GetName().c_str());
                ok = ok && attr.SerializeToJson(writer);
            }
            else
            {
                customAttributes.emplace_back(attr);
            }
        }

        if (customAttributes.size() > 0)
        {
            // Wrap up the cutom event attributes in a separate event_data field
            ok = ok && writer.Key(AwsMetricsAttributeKeyEventData);
            ok = ok && writer.StartObject();
            for (const auto& attr : customAttributes)
            {
                ok = ok && writer.Key(attr.GetName().c_str());
                ok = ok && attr.SerializeToJson(writer);
            }
            ok = ok && writer.EndObject();
        }

        ok = ok && writer.EndObject();
        return ok;
    }