Skip to content

Commit 9a0f507

Browse files
authored
(#289) Added information on generic string enum types (#302)
1 parent 4111eab commit 9a0f507

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

docs/in-depth/client/advanced/maui-aot.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ Create a new partial class that inherits from `JsonSerializerContext`. It shoul
7575
AllowTrailingCommas = true,
7676
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault,
7777
Converters = [
78-
typeof(JsonStringEnumConverter),
7978
typeof(DateTimeConverter),
8079
typeof(DateTimeOffsetConverter),
8180
typeof(TimeOnlyConverter),
@@ -86,6 +85,17 @@ Create a new partial class that inherits from `JsonSerializerContext`. It shoul
8685
{
8786
}
8887

88+
Enumerations (enum) are transmitted as strings. If you use an enum in any of your models, you will additionally have to add `typeof(JsonStringEnumConverter<TEnum>)` to the list of converters, where `TEnum` is the type of the enum you are using. Repeat this for each enum you are using. For example, let's say you have multiple models. One of your models is using the enum `CategoryType` and another model is using `CustomerType`, your Converters section would look like this:
89+
90+
Converters = [
91+
typeof(JsonStringEnumConverter<CategoryType>)
92+
typeof(JsonStringEnumConverter<CustomerType>)
93+
typeof(DateTimeConverter),
94+
typeof(DateTimeOffsetConverter),
95+
typeof(TimeOnlyConverter),
96+
typeof(SpatialGeoJsonConverter)
97+
]
98+
8999
Add a `JsonSerializable` attribute for each entity that is stored in your `DbContext` similar to the ones in the example above. Finally, install the modified `JsonSerializerContext` in the `MauiProgram.cs` as the second statment in the `CreateMauiApp` function:
90100

91101
DatasyncSerializer.JsonSerializerOptions.TypeInfoResolver = MySerializerContext.Default;
@@ -105,5 +115,4 @@ The property group should look something like the following:
105115

106116
## Having problems?
107117

108-
Unfortunately, the development team does not have much experience with releasing iOS applications, so is of limited help. While you can [add a discussion](https://github.com/CommunityToolkit/Datasync/discussions), you will probably get more assistance in the [MAUI](https://github.com/dotnet/maui) and [Entity Framework Core](https://github.com/dotnet/efcore) projects.
109-
118+
Unfortunately, the development team does not have much experience with releasing with Native AOT, so is of limited help. While you can [add a discussion](https://github.com/CommunityToolkit/Datasync/discussions), you will probably get more assistance in the [MAUI](https://github.com/dotnet/maui) and [Entity Framework Core](https://github.com/dotnet/efcore) projects.

0 commit comments

Comments
 (0)