diff --git a/src/Skybrud.Essentials.AspNetCore/Attributes/NewtonsoftJson/NewtonsoftJsonOnlyConfigurationAttribute.cs b/src/Skybrud.Essentials.AspNetCore/Attributes/NewtonsoftJson/NewtonsoftJsonOnlyConfigurationAttribute.cs deleted file mode 100644 index fea0cdf..0000000 --- a/src/Skybrud.Essentials.AspNetCore/Attributes/NewtonsoftJson/NewtonsoftJsonOnlyConfigurationAttribute.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using Microsoft.AspNetCore.Mvc; -using Skybrud.Essentials.AspNetCore.Filters.NewtonsoftJson; - -#pragma warning disable CS1591 - -namespace Skybrud.Essentials.AspNetCore.Attributes.NewtonsoftJson { - - /// - /// When added to an API controller, the output will be serialized to JSON using Newtonsoft.Json. - /// - [AttributeUsage(AttributeTargets.Class)] - [Obsolete("Use the class in the 'Skybrud.Essentials.AspNetCore.Json.Newtonsoft.Attributes' namespace instead.")] - public class NewtonsoftJsonOnlyConfigurationAttribute : TypeFilterAttribute { - - public NewtonsoftJsonOnlyConfigurationAttribute() : base(typeof(NewtonsoftJsonOnlyConfigurationFilter)) { - Order = 1; - } - - } - -} \ No newline at end of file diff --git a/src/Skybrud.Essentials.AspNetCore/Filters/NewtonsoftJson/NewtonsoftJsonOnlyConfigurationFilter.cs b/src/Skybrud.Essentials.AspNetCore/Filters/NewtonsoftJson/NewtonsoftJsonOnlyConfigurationFilter.cs deleted file mode 100644 index 12cdd2c..0000000 --- a/src/Skybrud.Essentials.AspNetCore/Filters/NewtonsoftJson/NewtonsoftJsonOnlyConfigurationFilter.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Buffers; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.Formatters; -using Microsoft.Extensions.Options; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using Newtonsoft.Json.Serialization; - -#pragma warning disable CS1591 - -namespace Skybrud.Essentials.AspNetCore.Filters.NewtonsoftJson { - - [Obsolete("Use the class in the 'Skybrud.Essentials.AspNetCore.Json.Newtonsoft.Filters' namespace instead.")] - public class NewtonsoftJsonOnlyConfigurationFilter : IResultFilter { - - private readonly ArrayPool _arrayPool; - private readonly MvcOptions _options; - - public NewtonsoftJsonOnlyConfigurationFilter(ArrayPool arrayPool, IOptionsSnapshot options) { - _arrayPool = arrayPool; - _options = options.Value; - } - - public void OnResultExecuted(ResultExecutedContext context) { } - - public virtual void OnResultExecuting(ResultExecutingContext context) { - - if (context.Result is not ObjectResult objectResult) return; - - JsonSerializerSettings serializerSettings = new() { - ContractResolver = new DefaultContractResolver(), - Converters = { new VersionConverter() }, - }; - - objectResult.Formatters.Clear(); - objectResult.Formatters.Add(new NewtonsoftJsonOutputFormatter(serializerSettings, _arrayPool, _options)); - - } - - } - -} \ No newline at end of file diff --git a/src/Skybrud.Essentials.AspNetCore/Models/Json/JsonBody.cs b/src/Skybrud.Essentials.AspNetCore/Models/Json/JsonBody.cs deleted file mode 100644 index 36ad9ca..0000000 --- a/src/Skybrud.Essentials.AspNetCore/Models/Json/JsonBody.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Net; -using Newtonsoft.Json; - -#pragma warning disable CS8618 - -namespace Skybrud.Essentials.AspNetCore.Models.Json { - - /// - /// Class representing the body of a JSON response. - /// - [Obsolete("Use the 'NewtonsoftJsonBody' class instead.")] - public class JsonBody { - - /// - /// Gets or sets the meta data for the response. - /// - [JsonProperty(PropertyName = "meta")] - public JsonMetaData Meta { get; set; } = new(); - - /// - /// Gets or sets the data object. - /// - [JsonProperty(PropertyName = "data", NullValueHandling = NullValueHandling.Ignore)] - public object Data { get; set; } - - #region Constructors - - /// - /// Initializes a new instance with default options. - /// - public JsonBody() { } - - /// - /// Initializes a new instance based on the specified and message. - /// - /// The HTTP status. - /// The error message. - public JsonBody(HttpStatusCode status, string error) { - Meta.Code = status; - Meta.Error = error; - } - - /// - /// Initializes a new instance based on the specified , message and . - /// - /// The HTTP status. - /// The error message. - /// The data. - public JsonBody(HttpStatusCode status, string error, object data) { - Meta.Code = status; - Meta.Error = error; - Data = data; - } - - #endregion - - } - -} \ No newline at end of file diff --git a/src/Skybrud.Essentials.AspNetCore/Models/Json/JsonMetaData.cs b/src/Skybrud.Essentials.AspNetCore/Models/Json/JsonMetaData.cs deleted file mode 100644 index 872bd39..0000000 --- a/src/Skybrud.Essentials.AspNetCore/Models/Json/JsonMetaData.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Net; -using Newtonsoft.Json; - -#pragma warning disable CS8618 - -namespace Skybrud.Essentials.AspNetCore.Models.Json { - - /// - /// Class representing the meta data of a JSON response. - /// - [Obsolete("Use the 'NewtonsoftJsonMetaData' class instead.")] - public class JsonMetaData { - - /// - /// Gets or sets the status code. - /// - [JsonProperty(PropertyName = "code")] - public HttpStatusCode Code { get; set; } - - /// - /// Gets or sets the error message. If the error message is NULL, the property will not be a part of the JSON response. - /// - [JsonProperty(PropertyName = "error", NullValueHandling = NullValueHandling.Ignore)] - public string Error { get; set; } - - } - -} \ No newline at end of file diff --git a/src/Skybrud.Essentials.AspNetCore/Models/Json/JsonNetResult.cs b/src/Skybrud.Essentials.AspNetCore/Models/Json/JsonNetResult.cs deleted file mode 100644 index 4adc1b2..0000000 --- a/src/Skybrud.Essentials.AspNetCore/Models/Json/JsonNetResult.cs +++ /dev/null @@ -1,116 +0,0 @@ -using System; -using System.Net; -using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json; - -#pragma warning disable CS8625 - -namespace Skybrud.Essentials.AspNetCore.Models.Json { - - /// - /// Class representing a JOSN based result serialized using Newtonsoft.Json. - /// - [Obsolete("Use the 'NewtonsoftJsonNetResult' class instead.")] - public class JsonNetResult : ContentResult { - - #region Constructors - - /// - /// Initializes a new 200 OK result wrapping the specified . - /// - /// The value/body of the result. The value will be serialized to JSON before being returned to the client. - public JsonNetResult(object value) : this(HttpStatusCode.OK, value) { } - - /// - /// Initializes a new result with wrapping the specified . - /// - /// The HTTP status code. - /// The value/body of the result. The value will be serialized to JSON before being returned to the client. - public JsonNetResult(HttpStatusCode status, object value) { - - // Serialize the data to a JSON string using JSON.net - string json = JsonConvert.SerializeObject(value, Formatting.None); - - StatusCode = (int) status; - ContentType = "application/json"; - Content = json; - - } - - #endregion - - #region Static methods - - /// - /// Returns a new 200 OK result with the specified . - /// - /// The value/body of the result. The value will be serialized to JSON before being returned to the client. - /// An instance of . - public static JsonNetResult Ok(object value) { - return new JsonNetResult(HttpStatusCode.OK, value); - } - - /// - /// Returns a new 201 Created result with the specified . - /// - /// The value/body of the result. The value will be serialized to JSON before being returned to the client. - /// An instance of . - public static JsonNetResult Created(object value) { - return new JsonNetResult(HttpStatusCode.Created, value); - } - - /// - /// Returns a new 400 Bad Request result with the specified message. - /// - /// A message describing the error. - /// An instance of . - public static JsonNetResult BadRequest(string error) { - JsonBody body = new(HttpStatusCode.BadRequest, error, null); - return new JsonNetResult(HttpStatusCode.BadRequest, body); - } - - /// - /// Returns a new 401 Unauthorized result with the specified message. - /// - /// A message describing the error. - /// An instance of . - public static JsonNetResult Unauthorized(string error) { - JsonBody body = new(HttpStatusCode.Unauthorized, error, null); - return new JsonNetResult(HttpStatusCode.Unauthorized, body); - } - - /// - /// Returns a new 403 Forbidden result with the specified message. - /// - /// A message describing the error. - /// An instance of . - public static JsonNetResult Forbidden(string error) { - JsonBody body = new(HttpStatusCode.Forbidden, error, null); - return new JsonNetResult(HttpStatusCode.Forbidden, body); - } - - /// - /// Returns a new 404 Not Found result with the specified message. - /// - /// A message describing the error. - /// An instance of . - public static JsonNetResult NotFound(string error) { - JsonBody body = new(HttpStatusCode.NotFound, error, null); - return new JsonNetResult(HttpStatusCode.NotFound, body); - } - - /// - /// Returns a new 500 Internal Server Error result with the specified message. - /// - /// A message describing the error. - /// An instance of . - public static JsonNetResult InternalError(string error) { - JsonBody body = new(HttpStatusCode.InternalServerError, error, null); - return new JsonNetResult(HttpStatusCode.InternalServerError, body); - } - - #endregion - - } - -} \ No newline at end of file diff --git a/src/Skybrud.Essentials.AspNetCore/Models/NewtonsoftJson/NewtonsoftJsonBody.cs b/src/Skybrud.Essentials.AspNetCore/Models/NewtonsoftJson/NewtonsoftJsonBody.cs deleted file mode 100644 index 43dc46b..0000000 --- a/src/Skybrud.Essentials.AspNetCore/Models/NewtonsoftJson/NewtonsoftJsonBody.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Net; -using Newtonsoft.Json; - -#pragma warning disable CS8618 - -namespace Skybrud.Essentials.AspNetCore.Models.NewtonsoftJson { - - /// - /// Class representing the body of a JSON response. - /// - [Obsolete("Use the class in the 'Skybrud.Essentials.AspNetCore.Json.Newtonsoft' namespace instead.")] - public class NewtonsoftJsonBody { - - /// - /// Gets or sets the meta data for the response. - /// - [JsonProperty(PropertyName = "meta")] - public NewtonsoftJsonMetaData Meta { get; set; } = new(); - - /// - /// Gets or sets the data object. - /// - [JsonProperty(PropertyName = "data", NullValueHandling = NullValueHandling.Ignore)] - public object Data { get; set; } - - #region Constructors - - /// - /// Initializes a new instance with default options. - /// - public NewtonsoftJsonBody() { } - - /// - /// Initializes a new instance based on the specified and message. - /// - /// The HTTP status. - /// The error message. - public NewtonsoftJsonBody(HttpStatusCode status, string error) { - Meta.Code = status; - Meta.Error = error; - } - - /// - /// Initializes a new instance based on the specified , message and . - /// - /// The HTTP status. - /// The error message. - /// The data. - public NewtonsoftJsonBody(HttpStatusCode status, string error, object data) { - Meta.Code = status; - Meta.Error = error; - Data = data; - } - - #endregion - - } - -} \ No newline at end of file diff --git a/src/Skybrud.Essentials.AspNetCore/Models/NewtonsoftJson/NewtonsoftJsonMetaData.cs b/src/Skybrud.Essentials.AspNetCore/Models/NewtonsoftJson/NewtonsoftJsonMetaData.cs deleted file mode 100644 index e618e61..0000000 --- a/src/Skybrud.Essentials.AspNetCore/Models/NewtonsoftJson/NewtonsoftJsonMetaData.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Net; -using Newtonsoft.Json; - -#pragma warning disable CS8618 - -namespace Skybrud.Essentials.AspNetCore.Models.NewtonsoftJson { - - /// - /// Class representing the meta data of a JSON response. - /// - [Obsolete("Use the class in the 'Skybrud.Essentials.AspNetCore.Json.Newtonsoft' namespace instead.")] - public class NewtonsoftJsonMetaData { - - /// - /// Gets or sets the status code. - /// - [JsonProperty(PropertyName = "code")] - public HttpStatusCode Code { get; set; } - - /// - /// Gets or sets the error message. If the error message is NULL, the property will not be a part of the JSON response. - /// - [JsonProperty(PropertyName = "error", NullValueHandling = NullValueHandling.Ignore)] - public string Error { get; set; } - - } - -} \ No newline at end of file diff --git a/src/Skybrud.Essentials.AspNetCore/Models/NewtonsoftJson/NewtonsoftJsonResult.cs b/src/Skybrud.Essentials.AspNetCore/Models/NewtonsoftJson/NewtonsoftJsonResult.cs deleted file mode 100644 index 87076b4..0000000 --- a/src/Skybrud.Essentials.AspNetCore/Models/NewtonsoftJson/NewtonsoftJsonResult.cs +++ /dev/null @@ -1,116 +0,0 @@ -using System; -using System.Net; -using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json; - -#pragma warning disable CS8625 - -namespace Skybrud.Essentials.AspNetCore.Models.NewtonsoftJson { - - /// - /// Class representing a JOSN based result serialized using Newtonsoft.Json. - /// - [Obsolete("Use the class in the 'Skybrud.Essentials.AspNetCore.Json.Newtonsoft' namespace instead.")] - public class NewtonsoftJsonResult : ContentResult { - - #region Constructors - - /// - /// Initializes a new 200 OK result wrapping the specified . - /// - /// The value/body of the result. The value will be serialized to JSON before being returned to the client. - public NewtonsoftJsonResult(object value) : this(HttpStatusCode.OK, value) { } - - /// - /// Initializes a new result with wrapping the specified . - /// - /// The HTTP status code. - /// The value/body of the result. The value will be serialized to JSON before being returned to the client. - public NewtonsoftJsonResult(HttpStatusCode status, object value) { - - // Serialize the data to a JSON string using JSON.net - string json = JsonConvert.SerializeObject(value, Formatting.None); - - StatusCode = (int) status; - ContentType = "application/json"; - Content = json; - - } - - #endregion - - #region Static methods - - /// - /// Returns a new 200 OK result with the specified . - /// - /// The value/body of the result. The value will be serialized to JSON before being returned to the client. - /// An instance of . - public static NewtonsoftJsonResult Ok(object value) { - return new NewtonsoftJsonResult(HttpStatusCode.OK, value); - } - - /// - /// Returns a new 201 Created result with the specified . - /// - /// The value/body of the result. The value will be serialized to JSON before being returned to the client. - /// An instance of . - public static NewtonsoftJsonResult Created(object value) { - return new NewtonsoftJsonResult(HttpStatusCode.Created, value); - } - - /// - /// Returns a new 400 Bad Request result with the specified message. - /// - /// A message describing the error. - /// An instance of . - public static NewtonsoftJsonResult BadRequest(string error) { - NewtonsoftJsonBody body = new(HttpStatusCode.BadRequest, error, null); - return new NewtonsoftJsonResult(HttpStatusCode.BadRequest, body); - } - - /// - /// Returns a new 401 Unauthorized result with the specified message. - /// - /// A message describing the error. - /// An instance of . - public static NewtonsoftJsonResult Unauthorized(string error) { - NewtonsoftJsonBody body = new(HttpStatusCode.Unauthorized, error, null); - return new NewtonsoftJsonResult(HttpStatusCode.Unauthorized, body); - } - - /// - /// Returns a new 403 Forbidden result with the specified message. - /// - /// A message describing the error. - /// An instance of . - public static NewtonsoftJsonResult Forbidden(string error) { - NewtonsoftJsonBody body = new(HttpStatusCode.Forbidden, error, null); - return new NewtonsoftJsonResult(HttpStatusCode.Forbidden, body); - } - - /// - /// Returns a new 404 Not Found result with the specified message. - /// - /// A message describing the error. - /// An instance of . - public static NewtonsoftJsonResult NotFound(string error) { - NewtonsoftJsonBody body = new(HttpStatusCode.NotFound, error, null); - return new NewtonsoftJsonResult(HttpStatusCode.NotFound, body); - } - - /// - /// Returns a new 500 Internal Server Error result with the specified message. - /// - /// A message describing the error. - /// An instance of . - public static NewtonsoftJsonResult InternalError(string error) { - NewtonsoftJsonBody body = new(HttpStatusCode.InternalServerError, error, null); - return new NewtonsoftJsonResult(HttpStatusCode.InternalServerError, body); - } - - #endregion - - } - -} \ No newline at end of file