/// <summary>
        /// Reads response elements from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
        {
            this.Changes.SyncState            = reader.ReadElementValue(XmlNamespace.Messages, XmlElementNames.SyncState);
            this.Changes.MoreChangesAvailable = !reader.ReadElementValue <bool>(XmlNamespace.Messages, this.GetIncludesLastInRangeXmlElementName());

            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.Changes);
            if (!reader.IsEmptyElement)
            {
                do
                {
                    reader.Read();

                    if (reader.IsStartElement())
                    {
                        TChange change = this.CreateChangeInstance();

                        switch (reader.LocalName)
                        {
                        case XmlElementNames.Create:
                            change.ChangeType = ChangeType.Create;
                            break;

                        case XmlElementNames.Update:
                            change.ChangeType = ChangeType.Update;
                            break;

                        case XmlElementNames.Delete:
                            change.ChangeType = ChangeType.Delete;
                            break;

                        case XmlElementNames.ReadFlagChange:
                            change.ChangeType = ChangeType.ReadFlagChange;
                            break;

                        default:
                            reader.SkipCurrentElement();
                            break;
                        }

                        if (change != null)
                        {
                            reader.Read();
                            reader.EnsureCurrentNodeIsStartElement();

                            switch (change.ChangeType)
                            {
                            case ChangeType.Delete:
                            case ChangeType.ReadFlagChange:
                                change.Id = change.CreateId();
                                change.Id.LoadFromXml(reader, change.Id.GetXmlElementName());

                                if (change.ChangeType == ChangeType.ReadFlagChange)
                                {
                                    reader.Read();
                                    reader.EnsureCurrentNodeIsStartElement();

                                    ItemChange itemChange = change as ItemChange;

                                    EwsUtilities.Assert(
                                        itemChange != null,
                                        "SyncResponse.ReadElementsFromXml",
                                        "ReadFlagChange is only valid on ItemChange");

                                    itemChange.IsRead = reader.ReadElementValue <bool>(XmlNamespace.Types, XmlElementNames.IsRead);
                                }

                                break;

                            default:
                                change.ServiceObject = EwsUtilities.CreateEwsObjectFromXmlElementName <TServiceObject>(
                                    reader.Service,
                                    reader.LocalName);

                                change.ServiceObject.LoadFromXml(
                                    reader,
                                    true,                         /* clearPropertyBag */
                                    this.propertySet,
                                    this.SummaryPropertiesOnly);
                                break;
                            }

                            reader.ReadEndElementIfNecessary(XmlNamespace.Types, change.ChangeType.ToString());

                            this.changes.Add(change);
                        }
                    }
                }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.Changes));
            }
        }
        /// <summary>
        /// Reads response elements from Json.
        /// </summary>
        /// <param name="responseObject">The response object.</param>
        /// <param name="service">The service.</param>
        internal override void ReadElementsFromJson(JsonObject responseObject, ExchangeService service)
        {
            this.Changes.SyncState            = responseObject.ReadAsString(XmlElementNames.SyncState);
            this.Changes.MoreChangesAvailable = !responseObject.ReadAsBool(this.GetIncludesLastInRangeXmlElementName());

            JsonObject changesElement = responseObject.ReadAsJsonObject(XmlElementNames.Changes);

            foreach (object changeElement in changesElement.ReadAsArray(XmlElementNames.Changes))
            {
                JsonObject jsonChange = changeElement as JsonObject;

                TChange change = this.CreateChangeInstance();

                string changeType = jsonChange.ReadAsString(XmlElementNames.ChangeType);

                switch (changeType)
                {
                case XmlElementNames.Create:
                    change.ChangeType = ChangeType.Create;
                    break;

                case XmlElementNames.Update:
                    change.ChangeType = ChangeType.Update;
                    break;

                case XmlElementNames.Delete:
                    change.ChangeType = ChangeType.Delete;
                    break;

                case XmlElementNames.ReadFlagChange:
                    change.ChangeType = ChangeType.ReadFlagChange;
                    break;

                default:
                    break;
                }

                if (change != null)
                {
                    switch (change.ChangeType)
                    {
                    case ChangeType.Delete:
                    case ChangeType.ReadFlagChange:
                        change.Id = change.CreateId();
                        JsonObject jsonChangeId = jsonChange.ReadAsJsonObject(this.GetChangeIdElementName());
                        change.Id.LoadFromJson(jsonChangeId, service);

                        if (change.ChangeType == ChangeType.ReadFlagChange)
                        {
                            ItemChange itemChange = change as ItemChange;

                            EwsUtilities.Assert(
                                itemChange != null,
                                "SyncResponse.ReadElementsFromJson",
                                "ReadFlagChange is only valid on ItemChange");

                            itemChange.IsRead = jsonChange.ReadAsBool(XmlElementNames.IsRead);
                        }

                        break;

                    default:
                        JsonObject jsonServiceObject = jsonChange.ReadAsJsonObject(this.GetChangeElementName());
                        change.ServiceObject = EwsUtilities.CreateEwsObjectFromXmlElementName <TServiceObject>(service, jsonServiceObject.ReadTypeString());

                        change.ServiceObject.LoadFromJson(
                            jsonServiceObject,
                            service,
                            true,                         /* clearPropertyBag */
                            this.propertySet,
                            this.SummaryPropertiesOnly);
                        break;
                    }

                    this.changes.Add(change);
                }
            }
        }