Skip to content

Commit bd181ec

Browse files
committed
Fixed the serialization problem
1 parent 44900bd commit bd181ec

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

Chapter06/Chapter06.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="AutoMapper" Version="13.0.1" />
11+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

Chapter06/Persistence/JsonPersistence.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using Azon.Web.Sdk.Components;
22
using Azon.Web.Sdk.Contracts;
3-
using System.Text.Json;
3+
using Newtonsoft.Json;
44

55
namespace Chapter06.Persistence;
66

7-
public class JsonPersistence
7+
public class JsonPersistence
88
: IFilePersistence
99
{
1010
public string FilePath { get; set; } = Path.Combine(Environment.CurrentDirectory, "Form.json");
@@ -13,10 +13,9 @@ public void Save(List<Control> controls)
1313
{
1414
var dtos = controls.Select(ControlMapper.ToDto).ToList();
1515

16-
var json = JsonSerializer.Serialize(dtos, options: new JsonSerializerOptions
16+
var json = JsonConvert.SerializeObject(dtos, Formatting.Indented, new JsonSerializerSettings
1717
{
18-
WriteIndented = true,
19-
IncludeFields = true
18+
TypeNameHandling = TypeNameHandling.All
2019
});
2120

2221
File.WriteAllText(FilePath, json);

0 commit comments

Comments
 (0)