public override CosmosCacheSession Read()

in src/CosmosCacheSessionConverterSTJ.cs [20:88]


        public override CosmosCacheSession Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            if (reader.TokenType == JsonTokenType.Null)
            {
                return null;
            }

            if (reader.TokenType != JsonTokenType.StartObject)
            {
                throw new JsonException("Expected start of object");
            }

            CosmosCacheSession cosmosCacheSession = new CosmosCacheSession();
            string content = null;
            bool hasSessionKey = false;

            while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
            {
                if (reader.TokenType != JsonTokenType.PropertyName)
                {
                    throw new JsonException("Expected property name");
                }

                string propertyName = reader.GetString();
                reader.Read();

                switch (propertyName)
                {
                    case IdAttributeName:
                        string sessionKey = reader.GetString();
                        hasSessionKey = true;
                        cosmosCacheSession.SessionKey = sessionKey;
                        break;

                    case ContentAttributeName:
                        content = reader.GetString();
                        cosmosCacheSession.Content = Convert.FromBase64String(content);
                        break;

                    case TtlAttributeName:
                        cosmosCacheSession.TimeToLive = reader.GetInt64();
                        break;

                    case SlidingAttributeName:
                        cosmosCacheSession.IsSlidingExpiration = reader.GetBoolean();
                        break;

                    case AbsoluteSlidingExpirationAttributeName:
                        cosmosCacheSession.AbsoluteSlidingExpiration = reader.GetInt64();
                        break;

                    case PkAttributeName:
                        cosmosCacheSession.PartitionKeyAttribute = reader.GetString();
                        break;
                }
            }

            if (!hasSessionKey)
            {
                throw new JsonException("Missing 'id' on Cosmos DB session item.");
            }

            if (content == null)
            {
                throw new JsonException("Missing 'content' on Cosmos DB session item.");
            }

            return cosmosCacheSession;
        }