11using System ;
22using System . Net ;
33using System . Linq ;
4- using Newtonsoft . Json ;
4+ using System . Text . Json ;
5+ using System . Text . Json . Serialization ;
56using System . Net . Http ;
67using System . Threading . Tasks ;
78using System . Net . Http . Headers ;
@@ -29,7 +30,6 @@ public class ContentstackClient : IContentstackClient
2930 {
3031 internal ContentstackRuntimePipeline ContentstackPipeline { get ; set ; }
3132 internal ContentstackClientOptions contentstackOptions ;
32- internal JsonSerializer serializer => JsonSerializer . Create ( SerializerSettings ) ;
3333
3434 #region Private
3535 private HttpClient _httpClient ;
@@ -39,7 +39,7 @@ public class ContentstackClient : IContentstackClient
3939 private string xUserAgent => $ "contentstack-management-dotnet/{ Version } ";
4040
4141 // OAuth token storage
42- private readonly Dictionary < string , OAuthTokens > _oauthTokens = new Dictionary < string , OAuthTokens > ( ) ;
42+ // private readonly Dictionary<string, OAuthTokens> _oauthTokens = new Dictionary<string, OAuthTokens>();
4343
4444 private bool _isRefreshingToken = false ;
4545 #endregion
@@ -51,7 +51,13 @@ public class ContentstackClient : IContentstackClient
5151 /// <summary>
5252 /// Get and Set method for deserialization.
5353 /// </summary>
54- public JsonSerializerSettings SerializerSettings { get ; set ; } = new JsonSerializerSettings ( ) ;
54+ public JsonSerializerOptions SerializerOptions { get ; set ; } = new JsonSerializerOptions ( ) ;
55+
56+ /// <summary>
57+ /// Compatibility property for models that haven't been migrated yet.
58+ /// Returns SerializerOptions for backward compatibility.
59+ /// </summary>
60+ internal JsonSerializerOptions serializer => SerializerOptions ;
5561
5662 #endregion
5763
@@ -190,18 +196,13 @@ protected void Initialize(HttpClient httpClient = null)
190196 }
191197 }
192198
193- SerializerSettings . DateParseHandling = DateParseHandling . None ;
194- SerializerSettings . DateFormatHandling = DateFormatHandling . IsoDateFormat ;
195- SerializerSettings . DateTimeZoneHandling = DateTimeZoneHandling . Utc ;
196- SerializerSettings . NullValueHandling = NullValueHandling . Ignore ;
199+ // Configure System.Text.Json options
200+ SerializerOptions . DefaultIgnoreCondition = JsonIgnoreCondition . WhenWritingNull ;
201+ SerializerOptions . PropertyNameCaseInsensitive = true ;
197202
198- foreach ( Type t in CsmJsonConverterAttribute . GetCustomAttribute ( typeof ( CsmJsonConverterAttribute ) ) )
199- {
200- SerializerSettings . Converters . Add ( ( JsonConverter ) Activator . CreateInstance ( t ) ) ;
201- }
202- SerializerSettings . Converters . Add ( new NodeJsonConverter ( ) ) ;
203- SerializerSettings . Converters . Add ( new TextNodeJsonConverter ( ) ) ;
204- SerializerSettings . Converters . Add ( new FieldJsonConverter ( ) ) ;
203+ // SerializerOptions.Converters.Add(new FieldJsonConverter()); // Excluded for now
204+ SerializerOptions . Converters . Add ( new NodeJsonConverter ( ) ) ;
205+ SerializerOptions . Converters . Add ( new TextNodeJsonConverter ( ) ) ;
205206 }
206207
207208 protected void BuildPipeline ( )
@@ -251,11 +252,13 @@ internal async Task<TResponse> InvokeAsync<TRequest, TResponse>(TRequest request
251252 {
252253 ThrowIfDisposed ( ) ;
253254
255+ /*
254256 // Check and refresh OAuth tokens if needed before making API calls
255257 if (contentstackOptions.IsOAuthToken && !string.IsNullOrEmpty(contentstackOptions.Authtoken))
256258 {
257259 await EnsureOAuthTokenIsValidAsync();
258260 }
261+ */
259262
260263 ExecutionContext context = new ExecutionContext (
261264 new RequestContext ( )
@@ -304,6 +307,7 @@ private void ThrowIfDisposed()
304307 }
305308 #endregion
306309
310+ /*
307311 /// <summary>
308312 /// <see cref="Models.User" /> session consists of calls that will help you to update user of your Contentstack account.
309313 /// </summary>
@@ -318,7 +322,9 @@ public User User()
318322 {
319323 return new User(this);
320324 }
325+ */
321326
327+ /*
322328 /// <summary>
323329 /// <see cref="Models.Organization" /> the top-level entity in the hierarchy of Contentstack, consisting of stacks and stack resources, and users.
324330 /// <see cref="Models.Organization" /> allows easy management of projects as well as users within the Organization.
@@ -335,7 +341,9 @@ public Organization Organization(string uid = null)
335341 {
336342 return new Organization(this, uid);
337343 }
344+ */
338345
346+ /*
339347 /// <summary>
340348 /// <see cref="Models.Stack" /> is a space that stores the content of a project (a web or mobile property).
341349 /// Within a stack, you can create content structures, content entries, users, etc. related to the project.
@@ -353,6 +361,7 @@ public Stack Stack(string apiKey = null, string managementToken = null, string b
353361 {
354362 return new Stack(this, apiKey, managementToken, branchUid);
355363 }
364+ */
356365
357366 #region LoginMethod
358367 /// <summary>
@@ -372,7 +381,7 @@ public Stack Stack(string apiKey = null, string managementToken = null, string b
372381 public ContentstackResponse Login ( ICredentials credentials , string token = null , string mfaSecret = null )
373382 {
374383 ThrowIfAlreadyLoggedIn ( ) ;
375- LoginService Login = new LoginService ( serializer , credentials , token , mfaSecret ) ;
384+ LoginService Login = new LoginService ( SerializerOptions , credentials , token , mfaSecret ) ;
376385
377386 return InvokeSync ( Login ) ;
378387 }
@@ -394,7 +403,7 @@ public ContentstackResponse Login(ICredentials credentials, string token = null,
394403 public Task < ContentstackResponse > LoginAsync ( ICredentials credentials , string token = null , string mfaSecret = null )
395404 {
396405 ThrowIfAlreadyLoggedIn ( ) ;
397- LoginService Login = new LoginService ( serializer , credentials , token , mfaSecret ) ;
406+ LoginService Login = new LoginService ( SerializerOptions , credentials , token , mfaSecret ) ;
398407
399408 return InvokeAsync < LoginService , ContentstackResponse > ( Login ) ;
400409 }
@@ -434,7 +443,7 @@ internal void ThrowIfNotLoggedIn()
434443 public ContentstackResponse Logout ( string authtoken = null )
435444 {
436445 string token = authtoken ?? contentstackOptions . Authtoken ;
437- LogoutService logout = new LogoutService ( serializer , token ) ;
446+ LogoutService logout = new LogoutService ( SerializerOptions , token ) ;
438447
439448 return InvokeSync ( logout ) ;
440449 }
@@ -452,12 +461,13 @@ public ContentstackResponse Logout(string authtoken = null)
452461 public Task < ContentstackResponse > LogoutAsync ( string authtoken = null )
453462 {
454463 string token = authtoken ?? contentstackOptions . Authtoken ;
455- LogoutService logout = new LogoutService ( serializer , token ) ;
464+ LogoutService logout = new LogoutService ( SerializerOptions , token ) ;
456465
457466 return InvokeAsync < LogoutService , ContentstackResponse > ( logout ) ;
458467 }
459468 #endregion
460469
470+ /*
461471 #region OAuth Methods
462472 /// <summary>
463473 /// Creates an OAuth handler for OAuth 2.0 authentication flow.
@@ -490,7 +500,9 @@ public OAuthHandler OAuth(OAuthOptions options)
490500
491501 return new OAuthHandler(this, options);
492502 }
503+ */
493504
505+ /*
494506 /// <summary>
495507 /// Creates an OAuth handler with default OAuth options.
496508 /// Uses the default AppId, ClientId, and RedirectUri.
@@ -510,7 +522,9 @@ public OAuthHandler OAuth()
510522 var defaultOptions = new OAuthOptions();
511523 return new OAuthHandler(this, defaultOptions);
512524 }
525+ */
513526
527+ /*
514528 /// <summary>
515529 /// Sets OAuth tokens for the client to use for authenticated requests.
516530 /// This method is called internally by the OAuthHandler after successful token exchange or refresh.
@@ -662,6 +676,7 @@ internal void ClearAllOAuthTokens()
662676 _oauthTokens.Clear();
663677 }
664678 #endregion
679+ */
665680
666681 /// <summary>
667682 /// The Get user call returns comprehensive information of an existing user account.
@@ -677,7 +692,7 @@ public ContentstackResponse GetUser(ParameterCollection collection = null)
677692 {
678693 ThrowIfNotLoggedIn ( ) ;
679694
680- GetLoggedInUserService getUser = new GetLoggedInUserService ( serializer , collection ) ;
695+ GetLoggedInUserService getUser = new GetLoggedInUserService ( SerializerOptions , collection ) ;
681696
682697 return InvokeSync ( getUser ) ;
683698 }
@@ -696,11 +711,12 @@ public Task<ContentstackResponse> GetUserAsync(ParameterCollection collection =
696711 {
697712 ThrowIfNotLoggedIn ( ) ;
698713
699- GetLoggedInUserService getUser = new GetLoggedInUserService ( serializer , collection ) ;
714+ GetLoggedInUserService getUser = new GetLoggedInUserService ( SerializerOptions , collection ) ;
700715
701716 return InvokeAsync < GetLoggedInUserService , ContentstackResponse > ( getUser ) ;
702717 }
703718
719+ /*
704720 /// <summary>
705721 /// Ensures that the current OAuth token is valid and refreshes it if needed.
706722 /// This method is called before each API request to automatically handle token refresh.
@@ -768,6 +784,7 @@ private async Task EnsureOAuthTokenIsValidAsync()
768784 $"OAuth token validation failed: {ex.Message}", ex);
769785 }
770786 }
787+ */
771788 }
772789}
773790
0 commit comments