Example #1
0
        /// <inheritdoc/>
        public override HttpContent SerializeBody <T>(T body, RequestBodySerializerInfo info)
        {
            var content = new StringContent(JsonConvert.SerializeObject(body, this.JsonSerializerSettings));

            content.Headers.ContentType.MediaType = "application/json";
            return(content);
        }
        /// <inheritdoc/>
        public override HttpContent?SerializeBody <T>(T body, RequestBodySerializerInfo info)
        {
            if (body == null)
            {
                return(null);
            }

            var content = new StringContent(JsonConvert.SerializeObject(body, this.JsonSerializerSettings));

            const string contentType = "application/json";

            if (content.Headers.ContentType == null)
            {
                content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
            }
            else
            {
                content.Headers.ContentType.MediaType = contentType;
            }
            return(content);
        }
Example #3
0
 public override HttpContent SerializeBody <T>(T body, RequestBodySerializerInfo info) =>
 this.serializer.SerializeBody(body);
Example #4
0
 /// <summary>
 /// Serialize the given request body
 /// </summary>
 /// <param name="body">Body to serialize</param>
 /// <param name="info">Extra information about the request</param>
 /// <typeparam name="T">Type of the body to serialize</typeparam>
 /// <returns>HttpContent to assign to the request</returns>
 public virtual HttpContent?SerializeBody <T>(T body, RequestBodySerializerInfo info)
 {
     throw new NotImplementedException($"You must override and implement SerializeBody<T>(T body, RequestBodySerializerInfo info) in {this.GetType().Name}");
 }
Example #5
0
 /// <summary>
 /// Serialize the given request body
 /// </summary>
 /// <param name="body">Body to serialize</param>
 /// <param name="info">Extra information about the request</param>
 /// <typeparam name="T">Type of the body to serialize</typeparam>
 /// <returns>HttpContent to assign to the request</returns>
 public virtual HttpContent SerializeBody <T>(T body, RequestBodySerializerInfo info)
 {
     throw new NotImplementedException("You must override and implement SerializeBody<T>(T body, RequestBodySerializerInfo info)");
 }