Skip to content

Commit e999cd3

Browse files
Merge pull request #180 from contentstack/enhc/DX-7589
feat: migrate Entry, Entry Variant and Variant Group modules to System.Text.Json
2 parents 6a8733b + 63895ff commit e999cd3

16 files changed

Lines changed: 94 additions & 118 deletions

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## [v1.0.0-beta.6](https://github.com/contentstack/contentstack-management-dotnet/tree/v1.0.0-beta.6)
4+
- **Entry, Entry Variant & Variant Group STJ Migration Complete**
5+
- Migrated Entry and EntryVariant modules from Newtonsoft.Json to System.Text.Json
6+
- Fully migrated VariantGroup module with VariantContentTypeLinkService using Utf8JsonWriter
7+
- Re-enabled Stack.VariantGroup() method for variant group operations
8+
- Updated service constructors to use JsonSerializerOptions instead of JsonSerializer
9+
- Enhanced variant group API integration with proper content type linking
10+
- Removed build exclusions for VariantGroup files to re-enable module functionality
11+
312
## [v1.0.0-beta.5](https://github.com/contentstack/contentstack-management-dotnet/tree/v1.0.0-beta.5)
413
- **Environment & Global Field STJ Migration**
514
- Migrated Environment and Global Field modules from Newtonsoft.Json to System.Text.Json
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System;
2-
using Newtonsoft.Json;
2+
using System.Text.Json.Serialization;
33

44
namespace Contentstack.Management.Core.Abstractions
55
{
6-
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
76
public interface IEntry
87
{
9-
[JsonProperty(propertyName: "title")]
8+
[JsonPropertyName("title")]
109
string Title { get; set; }
1110
}
1211
}

Contentstack.Management.Core/Models/ContentType.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ public override Task<ContentstackResponse> DeleteAsync(ParameterCollection? coll
155155
return base.DeleteAsync(collection);
156156
}
157157

158-
/*
159158
/// <summary>
160159
/// <see cref="Models.Entry" /> is the actual piece of content created using one of the defined content types.
161160
/// </summary>
@@ -177,6 +176,5 @@ public Entry Entry(string uid = null)
177176
ThrowIfUidEmpty();
178177
return new Entry(stack, Uid, uid);
179178
}
180-
*/
181179
}
182180
}

Contentstack.Management.Core/Models/Entry.cs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Threading.Tasks;
5+
using System.Text.Json;
56
using Contentstack.Management.Core.Abstractions;
67
using Contentstack.Management.Core.Queryable;
78
using Contentstack.Management.Core.Services.Models;
8-
using Newtonsoft.Json;
9-
using Newtonsoft.Json.Linq;
109

1110
namespace 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
}

Contentstack.Management.Core/Models/EntryVariant.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public ContentstackResponse Create(object model, ParameterCollection collection
8686
stack.ThrowIfNotLoggedIn();
8787
ThrowIfUidEmpty();
8888

89-
var service = new CreateUpdateService<object>(stack.client.serializer, stack, resourcePath, model, "entry", "PUT", collection: collection);
89+
var service = new CreateUpdateService<object>(stack, resourcePath, model, "entry", "PUT", collection: collection, stjOptions: stack.client.SerializerOptions);
9090
return stack.client.InvokeSync(service);
9191
}
9292

@@ -101,7 +101,7 @@ public Task<ContentstackResponse> CreateAsync(object model, ParameterCollection
101101
stack.ThrowIfNotLoggedIn();
102102
ThrowIfUidEmpty();
103103

104-
var service = new CreateUpdateService<object>(stack.client.serializer, stack, resourcePath, model, "entry", "PUT", collection: collection);
104+
var service = new CreateUpdateService<object>(stack, resourcePath, model, "entry", "PUT", collection: collection, stjOptions: stack.client.SerializerOptions);
105105
return stack.client.InvokeAsync<CreateUpdateService<object>, ContentstackResponse>(service);
106106
}
107107

@@ -137,7 +137,7 @@ public ContentstackResponse Fetch(ParameterCollection collection = null)
137137
stack.ThrowIfNotLoggedIn();
138138
ThrowIfUidEmpty();
139139

140-
var service = new FetchDeleteService(stack.client.serializer, stack, resourcePath, collection: collection);
140+
var service = new FetchDeleteService(stack, resourcePath, collection: collection);
141141
return stack.client.InvokeSync(service);
142142
}
143143

@@ -151,7 +151,7 @@ public Task<ContentstackResponse> FetchAsync(ParameterCollection collection = nu
151151
stack.ThrowIfNotLoggedIn();
152152
ThrowIfUidEmpty();
153153

154-
var service = new FetchDeleteService(stack.client.serializer, stack, resourcePath, collection: collection);
154+
var service = new FetchDeleteService(stack, resourcePath, collection: collection);
155155
return stack.client.InvokeAsync<FetchDeleteService, ContentstackResponse>(service);
156156
}
157157

@@ -165,7 +165,7 @@ public ContentstackResponse Delete(ParameterCollection collection = null)
165165
stack.ThrowIfNotLoggedIn();
166166
ThrowIfUidEmpty();
167167

168-
var service = new FetchDeleteService(stack.client.serializer, stack, resourcePath, "DELETE", collection: collection);
168+
var service = new FetchDeleteService(stack, resourcePath, "DELETE", collection: collection);
169169
return stack.client.InvokeSync(service);
170170
}
171171

@@ -179,7 +179,7 @@ public Task<ContentstackResponse> DeleteAsync(ParameterCollection collection = n
179179
stack.ThrowIfNotLoggedIn();
180180
ThrowIfUidEmpty();
181181

182-
var service = new FetchDeleteService(stack.client.serializer, stack, resourcePath, "DELETE", collection: collection);
182+
var service = new FetchDeleteService(stack, resourcePath, "DELETE", collection: collection);
183183
return stack.client.InvokeAsync<FetchDeleteService, ContentstackResponse>(service);
184184
}
185185

0 commit comments

Comments
 (0)