コード例 #1
0
        public static CosmosQueryResponse ConvertToCosmosQueryResponse(
            FeedResponse <CosmosElement> dynamicFeed,
            CosmosSerializationOptions cosmosSerializationOptions)
        {
            IJsonWriter jsonWriter;

            if (cosmosSerializationOptions != null)
            {
                jsonWriter = cosmosSerializationOptions.CreateCustomWriterCallback();
            }
            else
            {
                jsonWriter = JsonWriter.Create(JsonSerializationFormat.Text);
            }

            jsonWriter.WriteArrayStart();

            foreach (CosmosElement cosmosElement in dynamicFeed)
            {
                cosmosElement.WriteTo(jsonWriter);
            }

            jsonWriter.WriteArrayEnd();

            MemoryStream memoryStream = new MemoryStream(jsonWriter.GetResult());

            return(new CosmosQueryResponse(
                       dynamicFeed.Headers,
                       memoryStream,
                       dynamicFeed.Count,
                       dynamicFeed.ResponseContinuation,
                       dynamicFeed.QueryMetrics));
        }
コード例 #2
0
        internal static string GetStringWithPropertyNamingPolicy(CosmosSerializationOptions options, string name)
        {
            if (options != null && options.PropertyNamingPolicy == CosmosPropertyNamingPolicy.CamelCase)
            {
                return(CosmosSerializationUtil.ToCamelCase(name));
            }

            return(name);
        }
コード例 #3
0
        /// <summary>
        /// Create a serializer that uses the JSON.net serializer
        /// </summary>
        /// <remarks>
        /// This is internal to reduce exposure of JSON.net types so
        /// it is easier to convert to System.Text.Json
        /// </remarks>
        internal CosmosJsonDotNetSerializer(CosmosSerializationOptions cosmosSerializerOptions)
        {
            JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings()
            {
                NullValueHandling = cosmosSerializerOptions.IgnoreNullValues ? NullValueHandling.Ignore : NullValueHandling.Include,
                Formatting        = cosmosSerializerOptions.Indented ? Formatting.Indented : Formatting.None,
                ContractResolver  = cosmosSerializerOptions.PropertyNamingPolicy == CosmosPropertyNamingPolicy.CamelCase
                    ? new CamelCasePropertyNamesContractResolver()
                    : null
            };

            this.Serializer = JsonSerializer.Create(jsonSerializerSettings);
        }
コード例 #4
0
        internal static CosmosSerializerCore Create(
            CosmosSerializer customSerializer,
            CosmosSerializationOptions serializationOptions)
        {
            if (customSerializer != null && serializationOptions != null)
            {
                throw new ArgumentException("Customer serializer and serialization options can not be set at the same time.");
            }

            if (serializationOptions != null)
            {
                customSerializer = new CosmosJsonSerializerWrapper(new CosmosJsonDotNetSerializer(serializationOptions));
            }

            return(new CosmosSerializerCore(customSerializer));
        }
コード例 #5
0
        /// <summary>
        /// Create a serializer that uses the JSON.net serializer
        /// </summary>
        /// <remarks>
        /// This is internal to reduce exposure of JSON.net types so
        /// it is easier to convert to System.Text.Json
        /// </remarks>
        internal CosmosJsonDotNetSerializer(CosmosSerializationOptions cosmosSerializerOptions)
        {
            if (cosmosSerializerOptions == null)
            {
                this.SerializerSettings = null;
                return;
            }

            JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings()
            {
                NullValueHandling = cosmosSerializerOptions.IgnoreNullValues ? NullValueHandling.Ignore : NullValueHandling.Include,
                Formatting        = cosmosSerializerOptions.Indented ? Formatting.Indented : Formatting.None,
                ContractResolver  = cosmosSerializerOptions.PropertyNamingPolicy == CosmosPropertyNamingPolicy.CamelCase
                    ? new CamelCasePropertyNamesContractResolver()
                    : null,
                MaxDepth = 64, // https://github.com/advisories/GHSA-5crp-9r3c-p9vr
            };

            this.SerializerSettings = jsonSerializerSettings;
        }
コード例 #6
0
 internal static CosmosQueryResponse CreateResponse(
     FeedResponse <CosmosElement> feedResponse,
     CosmosSerializationOptions cosmosSerializationOptions)
 {
     return(FeedResponseBinder.ConvertToCosmosQueryResponse(feedResponse, null));
 }