From 95255f5f4e054d0669bc14432af990722efcb6c5 Mon Sep 17 00:00:00 2001 From: OMpawar-21 Date: Wed, 1 Jul 2026 12:21:10 +0530 Subject: [PATCH] feat: migrate internal model DTOs from [JsonProperty] to [JsonPropertyName] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replace Newtonsoft.Json [JsonProperty] with STJ [JsonPropertyName] in: Field.cs, MetaData.cs, Contenttype.cs, StackResponse.cs, ContentStackError.cs, OAuth.cs, OAuthService.cs (OAuthTokenResponse class) - Swap using Newtonsoft.Json → using System.Text.Json.Serialization in all above files - Migrate Model/OAuth.cs (OAuthAppAuthorizationResponse, OAuthAppAuthorizationData, OAuthUser, OAuthResponse) - OAuthService.cs retains using Newtonsoft.Json for JsonConvert calls --- .../CMA/ContentStackError.cs | 44 +++++++++---------- .../CMA/OAuth/OAuthService.cs | 15 ++++--- .../Model/Contenttype.cs | 4 +- contentstack.model.generator/Model/Field.cs | 12 ++--- .../Model/MetaData.cs | 16 +++---- contentstack.model.generator/Model/OAuth.cs | 20 ++++----- .../Model/StackResponse.cs | 6 +-- 7 files changed, 59 insertions(+), 58 deletions(-) diff --git a/contentstack.model.generator/CMA/ContentStackError.cs b/contentstack.model.generator/CMA/ContentStackError.cs index e831ad3..d6d8ab6 100644 --- a/contentstack.model.generator/CMA/ContentStackError.cs +++ b/contentstack.model.generator/CMA/ContentStackError.cs @@ -1,9 +1,9 @@ -using Newtonsoft.Json; -using System; +using System; using System.Collections.Generic; using System.Net; -using System.Runtime.Serialization; - +using System.Runtime.Serialization; +using System.Text.Json.Serialization; + namespace contentstack.CMA { /// @@ -13,7 +13,7 @@ namespace contentstack.CMA public class ContentstackException : Exception { #region Private Variables - private string _ErrorMessage = string.Empty; + private string _ErrorMessage = string.Empty; #endregion @@ -31,7 +31,7 @@ public class ContentstackException : Exception /// /// This is error message. /// - [JsonProperty("error_message")] + [JsonPropertyName("error_message")] public string ErrorMessage { get @@ -48,13 +48,13 @@ public string ErrorMessage /// /// This is error code. /// - [JsonProperty("error_code")] + [JsonPropertyName("error_code")] public int ErrorCode { get; set; } /// /// Set of errors in detail. /// - [JsonProperty("errors")] + [JsonPropertyName("errors")] public Dictionary Errors { get; set; } #endregion @@ -85,21 +85,21 @@ public ContentstackException(Exception exception) : base(exception.Message, exception.InnerException) { this.ErrorMessage = exception.Message; - } - - protected ContentstackException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } - - public ContentstackException(string message, Exception innerException) : base(message, innerException) - { - } - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - } + } + + protected ContentstackException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + + public ContentstackException(string message, Exception innerException) : base(message, innerException) + { + } + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + } #endregion - + } } diff --git a/contentstack.model.generator/CMA/OAuth/OAuthService.cs b/contentstack.model.generator/CMA/OAuth/OAuthService.cs index fa8c085..55ae9fa 100644 --- a/contentstack.model.generator/CMA/OAuth/OAuthService.cs +++ b/contentstack.model.generator/CMA/OAuth/OAuthService.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; +using System.Text.Json.Serialization; namespace contentstack.CMA.OAuth { @@ -408,25 +409,25 @@ internal static string GetDeveloperHubHostname(string baseHost) public class OAuthTokenResponse { - [JsonProperty("access_token")] + [JsonPropertyName("access_token")] public string AccessToken { get; set; } - [JsonProperty("refresh_token")] + [JsonPropertyName("refresh_token")] public string RefreshToken { get; set; } - [JsonProperty("token_type")] + [JsonPropertyName("token_type")] public string TokenType { get; set; } - [JsonProperty("expires_in")] + [JsonPropertyName("expires_in")] public int ExpiresIn { get; set; } - [JsonProperty("scope")] + [JsonPropertyName("scope")] public string Scope { get; set; } - [JsonProperty("organization_uid")] + [JsonPropertyName("organization_uid")] public string OrganizationUid { get; set; } - [JsonProperty("user_uid")] + [JsonPropertyName("user_uid")] public string UserUid { get; set; } // Computed property for expiration time diff --git a/contentstack.model.generator/Model/Contenttype.cs b/contentstack.model.generator/Model/Contenttype.cs index 0b6a593..fc91927 100644 --- a/contentstack.model.generator/Model/Contenttype.cs +++ b/contentstack.model.generator/Model/Contenttype.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using Newtonsoft.Json; +using System.Text.Json.Serialization; namespace contentstack.model.generator.Model { @@ -11,7 +11,7 @@ public class Contenttype public List Schema { get; set; } - [JsonProperty(propertyName: "reference_to")] + [JsonPropertyName("reference_to")] public string ReferenceTo { get; set; } } } diff --git a/contentstack.model.generator/Model/Field.cs b/contentstack.model.generator/Model/Field.cs index c06ad9f..1d03abe 100644 --- a/contentstack.model.generator/Model/Field.cs +++ b/contentstack.model.generator/Model/Field.cs @@ -1,25 +1,25 @@ using System.Collections.Generic; -using Newtonsoft.Json; +using System.Text.Json.Serialization; namespace contentstack.model.generator.Model { public class Field { - [JsonProperty(PropertyName = "display_name")] + [JsonPropertyName("display_name")] public string DisplayName { get; set; } public string Uid { get; set; } - [JsonProperty(PropertyName = "data_type")] + [JsonPropertyName("data_type")] public string DataType { get; set; } - [JsonProperty(PropertyName = "multiple")] + [JsonPropertyName("multiple")] public bool IsMultiple { get; set; } - [JsonProperty(PropertyName = "reference_to")] + [JsonPropertyName("reference_to")] public object ReferenceTo { get; set; } - [JsonProperty(PropertyName = "field_metadata")] + [JsonPropertyName("field_metadata")] public MetaData FieldMetadata { get; set; } public List Blocks { get; set; } diff --git a/contentstack.model.generator/Model/MetaData.cs b/contentstack.model.generator/Model/MetaData.cs index d1aa4b6..8ffed9d 100644 --- a/contentstack.model.generator/Model/MetaData.cs +++ b/contentstack.model.generator/Model/MetaData.cs @@ -1,28 +1,28 @@ -using Newtonsoft.Json; +using System.Text.Json.Serialization; namespace contentstack.model.generator.Model { public class MetaData { - [JsonProperty(PropertyName = "ref_multiple")] + [JsonPropertyName("ref_multiple")] public bool RefMultiple { get; set; } - [JsonProperty(PropertyName = "default_value")] + [JsonPropertyName("default_value")] public object DefaultValue { get; set; } - [JsonProperty(PropertyName = "ref_multiple_content_types")] + [JsonPropertyName("ref_multiple_content_types")] public bool RefMultipleContentType { get; set; } - [JsonProperty(PropertyName = "allow_rich_text")] + [JsonPropertyName("allow_rich_text")] public bool IsRichText { get; set; } - [JsonProperty(PropertyName = "markdown")] + [JsonPropertyName("markdown")] public bool IsMarkdown { get; set; } - [JsonProperty(PropertyName = "extension")] + [JsonPropertyName("extension")] public bool IsExtension { get; set; } - [JsonProperty(PropertyName = "allow_json_rte")] + [JsonPropertyName("allow_json_rte")] public bool IsJsonRTE { get; set; } } } diff --git a/contentstack.model.generator/Model/OAuth.cs b/contentstack.model.generator/Model/OAuth.cs index 4af86fc..a7a80b4 100644 --- a/contentstack.model.generator/Model/OAuth.cs +++ b/contentstack.model.generator/Model/OAuth.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using Newtonsoft.Json; +using System.Text.Json.Serialization; using contentstack.model.generator.Model; namespace Contentstack.Model.Generator.Model @@ -11,7 +11,7 @@ namespace Contentstack.Model.Generator.Model public class OAuthAppAuthorizationResponse { - [JsonProperty("data")] + [JsonPropertyName("data")] public OAuthAppAuthorizationData[] Data { get; set; } } @@ -21,11 +21,11 @@ public class OAuthAppAuthorizationResponse public class OAuthAppAuthorizationData { - [JsonProperty("authorization_uid")] + [JsonPropertyName("authorization_uid")] public string AuthorizationUid { get; set; } - [JsonProperty("user")] + [JsonPropertyName("user")] public OAuthUser User { get; set; } } @@ -33,7 +33,7 @@ public class OAuthAppAuthorizationData public class OAuthUser { - [JsonProperty("uid")] + [JsonPropertyName("uid")] public string Uid { get; set; } } @@ -178,23 +178,23 @@ public override string ToString() public class OAuthResponse { - [JsonProperty("access_token")] + [JsonPropertyName("access_token")] public string AccessToken { get; set; } - [JsonProperty("refresh_token")] + [JsonPropertyName("refresh_token")] public string RefreshToken { get; set; } - [JsonProperty("expires_in")] + [JsonPropertyName("expires_in")] public int ExpiresIn { get; set; } - [JsonProperty("organization_uid")] + [JsonPropertyName("organization_uid")] public string OrganizationUid { get; set; } - [JsonProperty("user_uid")] + [JsonPropertyName("user_uid")] public string UserUid { get; set; } } /// diff --git a/contentstack.model.generator/Model/StackResponse.cs b/contentstack.model.generator/Model/StackResponse.cs index 8d4c7b8..be0716a 100644 --- a/contentstack.model.generator/Model/StackResponse.cs +++ b/contentstack.model.generator/Model/StackResponse.cs @@ -1,14 +1,14 @@ using System; -using Newtonsoft.Json; +using System.Text.Json.Serialization; namespace Contentstack.Model.Generator.Model { public class StackResponse { - [JsonProperty(PropertyName = "api_key")] + [JsonPropertyName("api_key")] public string APIKey { get; set; } public string Name { get; set; } - [JsonProperty(PropertyName = "master_locale")] + [JsonPropertyName("master_locale")] public string MasterLocale { get; set; } public string Uid { get; set; } public string Description { get; set; }