public override object ReadJson()

in src/CosmosCacheSessionConverter.cs [22:72]


        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return null;
            }

            if (reader.TokenType != JsonToken.StartObject)
            {
                throw new JsonReaderException();
            }

            JObject jObject = JObject.Load(reader);
            CosmosCacheSession cosmosCacheSession = new CosmosCacheSession();

            if (!jObject.TryGetValue(CosmosCacheSessionConverter.IdAttributeName, out JToken idJToken))
            {
                throw new JsonReaderException("Missing 'id' on Cosmos DB session item.");
            }

            cosmosCacheSession.SessionKey = idJToken.Value<string>();

            if (!jObject.TryGetValue(CosmosCacheSessionConverter.ContentAttributeName, out JToken contentJToken))
            {
                throw new JsonReaderException("Missing 'content' on Cosmos DB session item.");
            }

            cosmosCacheSession.Content = Convert.FromBase64String(contentJToken.Value<string>());

            if (jObject.TryGetValue(CosmosCacheSessionConverter.TtlAttributeName, out JToken ttlJToken))
            {
                cosmosCacheSession.TimeToLive = ttlJToken.Value<long>();
            }

            if (jObject.TryGetValue(CosmosCacheSessionConverter.SlidingAttributeName, out JToken ttlSlidingExpirationJToken))
            {
                cosmosCacheSession.IsSlidingExpiration = ttlSlidingExpirationJToken.Value<bool>();
            }

            if (jObject.TryGetValue(CosmosCacheSessionConverter.AbsoluteSlidingExpirationAttributeName, out JToken absoluteSlidingExpirationJToken))
            {
                cosmosCacheSession.AbsoluteSlidingExpiration = absoluteSlidingExpirationJToken.Value<long>();
            }

            if (jObject.TryGetValue(CosmosCacheSessionConverter.PkAttributeName, out JToken pkDefinitionJToken))
            {
                cosmosCacheSession.PartitionKeyAttribute = pkDefinitionJToken.Value<string>();
            }

            return cosmosCacheSession;
        }