22using System . Collections . Generic ;
33using System . IO ;
44using System . Threading . Tasks ;
5+ using System . Text . Json ;
56using Contentstack . Management . Core . Abstractions ;
67using Contentstack . Management . Core . Queryable ;
78using Contentstack . Management . Core . Services . Models ;
8- using Newtonsoft . Json ;
9- using Newtonsoft . Json . Linq ;
109
1110namespace Contentstack . Management . Core . Models
1211{
@@ -211,10 +210,10 @@ public ContentstackResponse DeleteMultipleLocal(List<string> locales)
211210 stack . ThrowIfNotLoggedIn ( ) ;
212211 ThrowIfUidEmpty ( ) ;
213212
214- var service = new DeleteService < Dictionary < string , List < string > > > ( stack . client . serializer , stack , resourcePath , "entry" , new Dictionary < string , List < string > > ( )
213+ var service = new DeleteService < Dictionary < string , List < string > > > ( stack , resourcePath , "entry" , new Dictionary < string , List < string > > ( )
215214 {
216215 { "locales" , locales }
217- } ) ;
216+ } , stjOptions : stack . client . SerializerOptions ) ;
218217 return stack . client . InvokeSync ( service ) ;
219218 }
220219
@@ -235,10 +234,10 @@ public Task<ContentstackResponse> DeleteMultipleLocalAsync(List<string> locales)
235234 stack . ThrowIfNotLoggedIn ( ) ;
236235 ThrowIfUidEmpty ( ) ;
237236
238- var service = new DeleteService < Dictionary < string , List < string > > > ( stack . client . serializer , stack , resourcePath , "entry" , new Dictionary < string , List < string > > ( )
237+ var service = new DeleteService < Dictionary < string , List < string > > > ( stack , resourcePath , "entry" , new Dictionary < string , List < string > > ( )
239238 {
240239 { "locales" , locales }
241- } ) ;
240+ } , stjOptions : stack . client . SerializerOptions ) ;
242241 return stack . client . InvokeAsync < DeleteService < Dictionary < string , List < string > > > , ContentstackResponse > ( service ) ;
243242 }
244243
@@ -264,7 +263,7 @@ public ContentstackResponse Localize(IEntry model, string locale)
264263
265264 collection . Add ( "locale" , locale ) ;
266265
267- var service = new LocalizationService < IEntry > ( stack . client . serializer , stack , resourcePath , model , "entry" , collection ) ;
266+ var service = new LocalizationService < IEntry > ( stack . client . SerializerOptions , stack , resourcePath , model , "entry" , collection ) ;
268267 return stack . client . InvokeSync ( service ) ;
269268 }
270269
@@ -290,7 +289,7 @@ public Task<ContentstackResponse> LocalizeAsync(IEntry model, string locale)
290289
291290 collection . Add ( "locale" , locale ) ;
292291
293- var service = new LocalizationService < IEntry > ( stack . client . serializer , stack , resourcePath , model , "entry" , collection ) ;
292+ var service = new LocalizationService < IEntry > ( stack . client . SerializerOptions , stack , resourcePath , model , "entry" , collection ) ;
294293 return stack . client . InvokeAsync < LocalizationService < IEntry > , ContentstackResponse > ( service ) ;
295294 }
296295
@@ -314,7 +313,7 @@ public ContentstackResponse Unlocalize(string locale)
314313
315314 collection . Add ( "locale" , locale ) ;
316315
317- var service = new LocalizationService < IEntry > ( stack . client . serializer , stack , resourcePath , null , "entry" , collection , true ) ;
316+ var service = new LocalizationService < IEntry > ( stack . client . SerializerOptions , stack , resourcePath , null , "entry" , collection , true ) ;
318317 return stack . client . InvokeSync ( service ) ;
319318 }
320319
@@ -338,7 +337,7 @@ public Task<ContentstackResponse> UnlocalizeAsync(string locale)
338337
339338 collection . Add ( "locale" , locale ) ;
340339
341- var service = new LocalizationService < IEntry > ( stack . client . serializer , stack , resourcePath , null , "entry" , collection , true ) ;
340+ var service = new LocalizationService < IEntry > ( stack . client . SerializerOptions , stack , resourcePath , null , "entry" , collection , true ) ;
342341 return stack . client . InvokeAsync < LocalizationService < IEntry > , ContentstackResponse > ( service ) ;
343342 }
344343
@@ -357,7 +356,7 @@ public ContentstackResponse Locales()
357356 stack . ThrowIfNotLoggedIn ( ) ;
358357 ThrowIfUidEmpty ( ) ;
359358
360- var service = new LocaleService ( stack . client . serializer , stack , resourcePath ) ;
359+ var service = new LocaleService ( stack . client . SerializerOptions , stack , resourcePath ) ;
361360 return stack . client . InvokeSync ( service ) ;
362361 }
363362
@@ -376,7 +375,7 @@ public Task<ContentstackResponse> LocalesAsync()
376375 stack . ThrowIfNotLoggedIn ( ) ;
377376 ThrowIfUidEmpty ( ) ;
378377
379- var service = new LocaleService ( stack . client . serializer , stack , resourcePath ) ;
378+ var service = new LocaleService ( stack . client . SerializerOptions , stack , resourcePath ) ;
380379 return stack . client . InvokeAsync < LocaleService , ContentstackResponse > ( service ) ;
381380 }
382381
@@ -395,7 +394,7 @@ public ContentstackResponse References(ParameterCollection collection = null)
395394 stack . ThrowIfNotLoggedIn ( ) ;
396395 ThrowIfUidEmpty ( ) ;
397396
398- var service = new FetchReferencesService ( stack . client . serializer , stack , resourcePath , collection : collection ) ;
397+ var service = new FetchReferencesService ( stack , resourcePath , collection : collection , stjOptions : stack . client . SerializerOptions ) ;
399398 return stack . client . InvokeSync ( service ) ;
400399 }
401400
@@ -414,7 +413,7 @@ public Task<ContentstackResponse> ReferencesAsync(ParameterCollection collection
414413 stack . ThrowIfNotLoggedIn ( ) ;
415414 ThrowIfUidEmpty ( ) ;
416415
417- var service = new FetchReferencesService ( stack . client . serializer , stack , resourcePath , collection : collection ) ;
416+ var service = new FetchReferencesService ( stack , resourcePath , collection : collection , stjOptions : stack . client . SerializerOptions ) ;
418417 return stack . client . InvokeAsync < FetchReferencesService , ContentstackResponse > ( service ) ;
419418 }
420419
@@ -435,7 +434,7 @@ public virtual ContentstackResponse Publish(PublishUnpublishDetails details, str
435434 stack . ThrowIfNotLoggedIn ( ) ;
436435 ThrowIfUidEmpty ( ) ;
437436
438- var service = new PublishUnpublishService ( stack . client . serializer , stack , details , $ "{ resourcePath } /publish", "entry" , locale ) ;
437+ var service = new PublishUnpublishService ( stack , details , $ "{ resourcePath } /publish", "entry" , locale , stjOptions : stack . client . SerializerOptions ) ;
439438 return stack . client . InvokeSync ( service , apiVersion : apiVersion ) ;
440439 }
441440
@@ -456,7 +455,7 @@ public virtual Task<ContentstackResponse> PublishAsync(PublishUnpublishDetails d
456455 stack . ThrowIfNotLoggedIn ( ) ;
457456 ThrowIfUidEmpty ( ) ;
458457
459- var service = new PublishUnpublishService ( stack . client . serializer , stack , details , $ "{ resourcePath } /publish", "entry" , locale ) ;
458+ var service = new PublishUnpublishService ( stack , details , $ "{ resourcePath } /publish", "entry" , locale , stjOptions : stack . client . SerializerOptions ) ;
460459 return stack . client . InvokeAsync < PublishUnpublishService , ContentstackResponse > ( service , apiVersion : apiVersion ) ;
461460 }
462461
@@ -477,7 +476,7 @@ public virtual ContentstackResponse Unpublish(PublishUnpublishDetails details, s
477476 stack . ThrowIfNotLoggedIn ( ) ;
478477 ThrowIfUidEmpty ( ) ;
479478
480- var service = new PublishUnpublishService ( stack . client . serializer , stack , details , $ "{ resourcePath } /unpublish", "entry" , locale ) ;
479+ var service = new PublishUnpublishService ( stack , details , $ "{ resourcePath } /unpublish", "entry" , locale , stjOptions : stack . client . SerializerOptions ) ;
481480 return stack . client . InvokeSync ( service , apiVersion : apiVersion ) ;
482481 }
483482
@@ -498,7 +497,7 @@ public virtual Task<ContentstackResponse> UnpublishAsync(PublishUnpublishDetails
498497 stack . ThrowIfNotLoggedIn ( ) ;
499498 ThrowIfUidEmpty ( ) ;
500499
501- var service = new PublishUnpublishService ( stack . client . serializer , stack , details , $ "{ resourcePath } /unpublish", "entry" , locale ) ;
500+ var service = new PublishUnpublishService ( stack , details , $ "{ resourcePath } /unpublish", "entry" , locale , stjOptions : stack . client . SerializerOptions ) ;
502501 return stack . client . InvokeAsync < PublishUnpublishService , ContentstackResponse > ( service , apiVersion : apiVersion ) ;
503502 }
504503
@@ -520,7 +519,7 @@ public ContentstackResponse Import(string filePath, ParameterCollection collecti
520519 stack . ThrowIfNotLoggedIn ( ) ;
521520
522521 var text = File . ReadAllText ( filePath ) ;
523- var service = new ImportExportService ( stack . client . serializer , stack , resourcePath , true , "POST" , collection ) ;
522+ var service = new ImportExportService ( stack . client . SerializerOptions , stack , resourcePath , true , "POST" , collection ) ;
524523 service . ByteContent = System . Text . Encoding . UTF8 . GetBytes ( text ) ;
525524
526525 return stack . client . InvokeSync ( service ) ;
@@ -545,7 +544,7 @@ public Task<ContentstackResponse> ImportAsync(string filePath, ParameterCollecti
545544 ThrowIfUidEmpty ( ) ;
546545
547546 var text = File . ReadAllText ( filePath ) ;
548- var service = new ImportExportService ( stack . client . serializer , stack , resourcePath , isImport : true , "POST" , collection ) ;
547+ var service = new ImportExportService ( stack . client . SerializerOptions , stack , resourcePath , isImport : true , "POST" , collection ) ;
549548 service . ByteContent = System . Text . Encoding . UTF8 . GetBytes ( text ) ;
550549 return stack . client . InvokeAsync < ImportExportService , ContentstackResponse > ( service ) ;
551550 }
@@ -569,16 +568,13 @@ public ContentstackResponse Export(string filePath, ParameterCollection collecti
569568
570569 try
571570 {
572- var service = new ImportExportService ( stack . client . serializer , stack , resourcePath , collection : collection ) ;
571+ var service = new ImportExportService ( stack . client . SerializerOptions , stack , resourcePath , collection : collection ) ;
573572 ContentstackResponse response = stack . client . InvokeSync ( service ) ;
574573 if ( response . IsSuccessStatusCode )
575574 {
576- using ( StreamWriter file = File . CreateText ( filePath ) )
577- using ( JsonTextWriter writer = new JsonTextWriter ( file ) )
578- {
579- JObject json = response . OpenJObjectResponse ( ) ;
580- json . WriteTo ( writer ) ;
581- }
575+ var json = response . OpenJsonObjectResponse ( ) ;
576+ var opts = new JsonSerializerOptions { WriteIndented = true } ;
577+ File . WriteAllText ( filePath , json . ToJsonString ( opts ) ) ;
582578 }
583579 return response ;
584580 } catch ( Exception e )
@@ -609,7 +605,7 @@ public ContentstackResponse SetWorkflow(EntryWorkflowStage model, ParameterColle
609605 {
610606 { "workflow_stage" , model }
611607 } ;
612- var service = new CreateUpdateService < Dictionary < string , EntryWorkflowStage > > ( stack . client . serializer , stack , $ "{ resourcePath } /workflow", dict , "workflow" , collection : collection ) ;
608+ var service = new CreateUpdateService < Dictionary < string , EntryWorkflowStage > > ( stack , $ "{ resourcePath } /workflow", dict , "workflow" , collection : collection , stjOptions : stack . client . SerializerOptions ) ;
613609 return stack . client . InvokeSync ( service ) ;
614610 }
615611
@@ -634,7 +630,7 @@ public Task<ContentstackResponse> SetWorkflowAsync(EntryWorkflowStage model, Par
634630 {
635631 { "workflow_stage" , model }
636632 } ;
637- var service = new CreateUpdateService < Dictionary < string , EntryWorkflowStage > > ( stack . client . serializer , stack , $ "{ resourcePath } /workflow", dict , "workflow" , collection : collection ) ;
633+ var service = new CreateUpdateService < Dictionary < string , EntryWorkflowStage > > ( stack , $ "{ resourcePath } /workflow", dict , "workflow" , collection : collection , stjOptions : stack . client . SerializerOptions ) ;
638634 return stack . client . InvokeAsync < CreateUpdateService < Dictionary < string , EntryWorkflowStage > > , ContentstackResponse > ( service ) ;
639635 }
640636
@@ -659,7 +655,7 @@ public ContentstackResponse PublishRequest(EntryPublishAction publishAction, Par
659655 {
660656 { "publishing_rule" , publishAction }
661657 } ;
662- var service = new CreateUpdateService < Dictionary < string , EntryPublishAction > > ( stack . client . serializer , stack , $ "{ resourcePath } /workflow", dict , "workflow" , collection : collection ) ;
658+ var service = new CreateUpdateService < Dictionary < string , EntryPublishAction > > ( stack , $ "{ resourcePath } /workflow", dict , "workflow" , collection : collection , stjOptions : stack . client . SerializerOptions ) ;
663659 return stack . client . InvokeSync ( service ) ;
664660 }
665661 /// <summary>
@@ -683,7 +679,7 @@ public Task<ContentstackResponse> PublishRequestAsync(EntryPublishAction publish
683679 {
684680 { "publishing_rule" , publishAction }
685681 } ;
686- var service = new CreateUpdateService < Dictionary < string , EntryPublishAction > > ( stack . client . serializer , stack , $ "{ resourcePath } /workflow", dict , "workflow" , collection : collection ) ;
682+ var service = new CreateUpdateService < Dictionary < string , EntryPublishAction > > ( stack , $ "{ resourcePath } /workflow", dict , "workflow" , collection : collection , stjOptions : stack . client . SerializerOptions ) ;
687683 return stack . client . InvokeAsync < CreateUpdateService < Dictionary < string , EntryPublishAction > > , ContentstackResponse > ( service ) ;
688684 }
689685 }
0 commit comments