diff --git a/src/DragonFly.API.Core/Assets/RestAsset.cs b/src/DragonFly.API.Core/Assets/RestAsset.cs
index f7ebe83d..307ae691 100644
--- a/src/DragonFly.API.Core/Assets/RestAsset.cs
+++ b/src/DragonFly.API.Core/Assets/RestAsset.cs
@@ -11,11 +11,6 @@ namespace DragonFly.API;
///
public class RestAsset : RestContentBase
{
- public RestAsset()
- {
- _metaddata = new JsonObject();
- }
-
///
/// Name
///
@@ -61,10 +56,8 @@ public RestAsset()
///
public virtual RestAssetFolder Folder { get; set; }
- private JsonObject _metaddata;
-
///
/// Metaddata
///
- public virtual JsonObject Metaddata { get => _metaddata; set => _metaddata = value; }
+ public virtual JsonObject Metaddata { get; set; } = new JsonObject();
}
diff --git a/src/DragonFly.API.Core/ContentItems/RestContentItem.cs b/src/DragonFly.API.Core/ContentItems/RestContentItem.cs
index ee07c953..25932335 100644
--- a/src/DragonFly.API.Core/ContentItems/RestContentItem.cs
+++ b/src/DragonFly.API.Core/ContentItems/RestContentItem.cs
@@ -13,11 +13,6 @@ namespace DragonFly.API;
///
public class RestContentItem : RestContentBase
{
- public RestContentItem()
- {
- Fields = new JsonObject();
- }
-
///
/// Schema
///
@@ -41,6 +36,6 @@ public RestContentItem()
///
[JsonPropertyOrder(30)]
//[JsonConverter(typeof(MyConverter))]
- public JsonObject Fields { get; set; }
+ public JsonObject Fields { get; set; } = new JsonObject();
}
diff --git a/src/DragonFly.API.Core/Extensions/DragonFlyBuilderExtensions.cs b/src/DragonFly.API.Core/Extensions/DragonFlyBuilderExtensions.cs
deleted file mode 100644
index 3790094b..00000000
--- a/src/DragonFly.API.Core/Extensions/DragonFlyBuilderExtensions.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright (c) usercode
-// https://github.com/usercode/DragonFly
-// MIT License
-
-using System.Text.Json.Serialization.Metadata;
-using DragonFly.API;
-using DragonFly.Builders;
-
-namespace DragonFly;
-
-public static class DragonFlyBuilderExtensions
-{
- ///
- /// Adds a JsonSerializerContext to the REST api.
- ///
- ///
- ///
- ///
- public static TDragonFlyBuilder AddRestSerializerResolver(this TDragonFlyBuilder builder, IJsonTypeInfoResolver resolver)
- where TDragonFlyBuilder : IDragonFlyBuilder
- {
- ApiJsonSerializerDefault.Options.TypeInfoResolverChain.Add(resolver);
-
- return builder;
- }
-}
diff --git a/src/DragonFly.API.Core/Json/ApiJsonSerializerContext.cs b/src/DragonFly.API.Core/Json/ApiJsonSerializerContext.cs
deleted file mode 100644
index b6b8e506..00000000
--- a/src/DragonFly.API.Core/Json/ApiJsonSerializerContext.cs
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright (c) usercode
-// https://github.com/usercode/DragonFly
-// MIT License
-
-using System.Text.Json;
-using System.Text.Json.Serialization;
-using DragonFly.Query;
-
-namespace DragonFly.API;
-
-//Model
-[JsonSerializable(typeof(ResourceCreated))]
-[JsonSerializable(typeof(RestContentItem))]
-[JsonSerializable(typeof(RestContentSchema))]
-[JsonSerializable(typeof(RestAsset))]
-[JsonSerializable(typeof(RestAssetFolder))]
-[JsonSerializable(typeof(QueryResult))]
-[JsonSerializable(typeof(QueryResult))]
-[JsonSerializable(typeof(QueryResult))]
-[JsonSerializable(typeof(QueryResult))]
-[JsonSerializable(typeof(QueryResult))]
-[JsonSerializable(typeof(QueryResult))]
-[JsonSerializable(typeof(QueryResult))]
-[JsonSerializable(typeof(QueryResult))]
-[JsonSerializable(typeof(AssetQuery))]
-[JsonSerializable(typeof(AssetFolderQuery))]
-[JsonSerializable(typeof(ContentQuery))]
-[JsonSerializable(typeof(StructureQuery))]
-[JsonSerializable(typeof(WebHookQuery))]
-[JsonSerializable(typeof(IBackgroundTaskInfo))]
-[JsonSerializable(typeof(BackgroundTaskInfo))]
-[JsonSerializable(typeof(IEnumerable))]
-[JsonSerializable(typeof(ContentVersionEntry))]
-[JsonSerializable(typeof(IEnumerable))]
-
-//AssetMetadata
-[JsonSerializable(typeof(ImageMetadata))]
-[JsonSerializable(typeof(PdfMetadata))]
-[JsonSerializable(typeof(VideoMetadata))]
-
-//Field
-[JsonSerializable(typeof(ArrayField))]
-[JsonSerializable(typeof(AssetField))]
-[JsonSerializable(typeof(BoolField))]
-[JsonSerializable(typeof(ColorField))]
-[JsonSerializable(typeof(ComponentField))]
-[JsonSerializable(typeof(DateTimeField))]
-[JsonSerializable(typeof(FloatField))]
-[JsonSerializable(typeof(GeolocationField))]
-[JsonSerializable(typeof(HtmlField))]
-[JsonSerializable(typeof(IntegerField))]
-[JsonSerializable(typeof(ReferenceField))]
-[JsonSerializable(typeof(SlugField))]
-[JsonSerializable(typeof(StringField))]
-[JsonSerializable(typeof(TextField))]
-[JsonSerializable(typeof(UrlField))]
-[JsonSerializable(typeof(XmlField))]
-[JsonSerializable(typeof(BlockField))]
-
-//FieldOptions
-[JsonSerializable(typeof(ArrayFieldOptions))]
-[JsonSerializable(typeof(AssetFieldOptions))]
-[JsonSerializable(typeof(BoolFieldOptions))]
-[JsonSerializable(typeof(ColorFieldOptions))]
-[JsonSerializable(typeof(ComponentFieldOptions))]
-[JsonSerializable(typeof(DateTimeFieldOptions))]
-[JsonSerializable(typeof(FloatFieldOptions))]
-[JsonSerializable(typeof(GeolocationFieldOptions))]
-[JsonSerializable(typeof(HtmlFieldOptions))]
-[JsonSerializable(typeof(IntegerFieldOptions))]
-[JsonSerializable(typeof(ReferenceFieldOptions))]
-[JsonSerializable(typeof(SlugFieldOptions))]
-[JsonSerializable(typeof(StringFieldOptions))]
-[JsonSerializable(typeof(TextFieldOptions))]
-[JsonSerializable(typeof(UrlFieldOptions))]
-[JsonSerializable(typeof(XmlFieldOptions))]
-[JsonSerializable(typeof(BlockFieldOptions))]
-
-//FieldQuery
-[JsonSerializable(typeof(StringFieldQuery))]
-[JsonSerializable(typeof(BoolFieldQuery))]
-[JsonSerializable(typeof(FloatFieldQuery))]
-[JsonSerializable(typeof(GeolocationFieldQuery))]
-[JsonSerializable(typeof(IntegerFieldQuery))]
-[JsonSerializable(typeof(ReferenceFieldQuery))]
-[JsonSerializable(typeof(SlugFieldQuery))]
-[JsonSerializable(typeof(StringFieldQuery))]
-
-//defaults
-[JsonSourceGenerationOptions(JsonSerializerDefaults.Web)]
-internal partial class ApiJsonSerializerContext : JsonSerializerContext
-{
-}
diff --git a/src/DragonFly.API.Core/Json/ApiJsonTypeInfoResolver.cs b/src/DragonFly.API.Core/Json/ApiJsonTypeInfoResolver.cs
index cebafd0b..f8d23082 100644
--- a/src/DragonFly.API.Core/Json/ApiJsonTypeInfoResolver.cs
+++ b/src/DragonFly.API.Core/Json/ApiJsonTypeInfoResolver.cs
@@ -7,7 +7,7 @@
namespace DragonFly.API;
-public class ApiJsonTypeInfoResolver : IJsonTypeInfoResolver
+public class ApiJsonTypeInfoResolver : DefaultJsonTypeInfoResolver
{
///
/// Default
@@ -18,34 +18,31 @@ private ApiJsonTypeInfoResolver()
{
}
- public JsonTypeInfo? GetTypeInfo(Type type, JsonSerializerOptions options)
+ public override JsonTypeInfo GetTypeInfo(Type type, JsonSerializerOptions options)
{
- JsonTypeInfo? jsonInfoType = ((IJsonTypeInfoResolver)ApiJsonSerializerContext.Default).GetTypeInfo(type, options);
+ JsonTypeInfo jsonInfoType = base.GetTypeInfo(type, options);
- if (jsonInfoType != null)
+ if (jsonInfoType.Type == typeof(FieldOptions))
{
- if (jsonInfoType.Type == typeof(FieldOptions))
- {
- JsonPolymorphismOptions optionsDerivedTypes = new JsonPolymorphismOptions();
-
- foreach (Type t in FieldManager.Default.GetAllOptionsTypes())
- {
- optionsDerivedTypes.DerivedTypes.Add(new JsonDerivedType(t, t.Name));
- }
+ JsonPolymorphismOptions optionsDerivedTypes = new JsonPolymorphismOptions();
- jsonInfoType.PolymorphismOptions = optionsDerivedTypes;
- }
- else if (jsonInfoType.Type == typeof(FieldQuery))
+ foreach (Type t in FieldManager.Default.GetAllOptionsTypes())
{
- JsonPolymorphismOptions queryDerivedTypes = new JsonPolymorphismOptions();
+ optionsDerivedTypes.DerivedTypes.Add(new JsonDerivedType(t, t.Name));
+ }
- foreach (Type t in FieldManager.Default.GetAllQueryTypes())
- {
- queryDerivedTypes.DerivedTypes.Add(new JsonDerivedType(t, t.Name));
- }
+ jsonInfoType.PolymorphismOptions = optionsDerivedTypes;
+ }
+ else if (jsonInfoType.Type == typeof(FieldQuery))
+ {
+ JsonPolymorphismOptions queryDerivedTypes = new JsonPolymorphismOptions();
- jsonInfoType.PolymorphismOptions = queryDerivedTypes;
+ foreach (Type t in FieldManager.Default.GetAllQueryTypes())
+ {
+ queryDerivedTypes.DerivedTypes.Add(new JsonDerivedType(t, t.Name));
}
+
+ jsonInfoType.PolymorphismOptions = queryDerivedTypes;
}
return jsonInfoType;
diff --git a/src/DragonFly.API.Core/Json/Serializers/Fields/AssetJsonFieldSerializer.cs b/src/DragonFly.API.Core/Json/Serializers/Fields/AssetJsonFieldSerializer.cs
index 382880cb..c00f096b 100644
--- a/src/DragonFly.API.Core/Json/Serializers/Fields/AssetJsonFieldSerializer.cs
+++ b/src/DragonFly.API.Core/Json/Serializers/Fields/AssetJsonFieldSerializer.cs
@@ -16,7 +16,7 @@ public override AssetField Read(SchemaField schemaField, JsonNode? jsonValue)
{
AssetField contentField = new AssetField();
- RestAsset? restAsset = jsonValue.Deserialize(ApiJsonSerializerContext.Default.RestAsset);
+ RestAsset? restAsset = jsonValue.Deserialize(ApiJsonSerializerDefault.Options);
if (restAsset != null)
{
@@ -30,7 +30,7 @@ public override AssetField Read(SchemaField schemaField, JsonNode? jsonValue)
{
if (contentField.Asset != null)
{
- return JsonSerializer.SerializeToNode(contentField.Asset.ToRest(), ApiJsonSerializerContext.Default.RestAsset);
+ return JsonSerializer.SerializeToNode(contentField.Asset.ToRest(), ApiJsonSerializerDefault.Options);
}
else
{
diff --git a/src/DragonFly.ApiKeys.Client/DragonFlyBuilderExtensions.cs b/src/DragonFly.ApiKeys.Client/DragonFlyBuilderExtensions.cs
index 78c230cc..63db22b5 100644
--- a/src/DragonFly.ApiKeys.Client/DragonFlyBuilderExtensions.cs
+++ b/src/DragonFly.ApiKeys.Client/DragonFlyBuilderExtensions.cs
@@ -15,7 +15,6 @@ public static class DragonFlyBuilderExtensions
public static IDragonFlyBuilder AddApiKeys(this IDragonFlyBuilder builder)
{
builder.AddRazorRouting();
- builder.AddRestSerializerResolver(ApiKeysSerializerContext.Default);
builder.Services.AddTransient();
diff --git a/src/DragonFly.ApiKeys.Client/Services/ApiKeyService.cs b/src/DragonFly.ApiKeys.Client/Services/ApiKeyService.cs
index 5f804f66..fc28f17f 100644
--- a/src/DragonFly.ApiKeys.Client/Services/ApiKeyService.cs
+++ b/src/DragonFly.ApiKeys.Client/Services/ApiKeyService.cs
@@ -7,6 +7,7 @@
using System.Threading.Tasks;
using System.Net.Http.Json;
using System.Net.Http;
+using DragonFly.API;
namespace DragonFly.ApiKeys.Razor.Services;
@@ -24,14 +25,14 @@ public ApiKeyService(HttpClient client)
public async Task CreateApiKey(ApiKey apiKey)
{
- HttpResponseMessage response = await Client.PostAsJsonAsync("api/apikey", apiKey, ApiKeysSerializerContext.Default.ApiKey);
+ HttpResponseMessage response = await Client.PostAsJsonAsync("api/apikey", apiKey, ApiJsonSerializerDefault.Options);
response.EnsureSuccessStatusCode();
}
public async Task UpdateApiKey(ApiKey apiKey)
{
- HttpResponseMessage response = await Client.PutAsJsonAsync("api/apikey", apiKey, ApiKeysSerializerContext.Default.ApiKey);
+ HttpResponseMessage response = await Client.PutAsJsonAsync("api/apikey", apiKey, ApiJsonSerializerDefault.Options);
response.EnsureSuccessStatusCode();
}
@@ -49,7 +50,7 @@ public async Task> QueryApiKeys()
response.EnsureSuccessStatusCode();
- IEnumerable? result = await response.Content.ReadFromJsonAsync(ApiKeysSerializerContext.Default.IEnumerableApiKey);
+ IEnumerable? result = await response.Content.ReadFromJsonAsync>(ApiJsonSerializerDefault.Options);
if (result == null)
{
@@ -66,7 +67,7 @@ public Task GetApiKey(string value)
public async Task GetApiKey(Guid id)
{
- ApiKey? apikey = await Client.GetFromJsonAsync($"api/apikey/{id}", ApiKeysSerializerContext.Default.ApiKey);
+ ApiKey? apikey = await Client.GetFromJsonAsync($"api/apikey/{id}", ApiJsonSerializerDefault.Options);
if (apikey == null)
{
diff --git a/src/DragonFly.ApiKeys.Core/Json/ApiKeysSerializerContext.cs b/src/DragonFly.ApiKeys.Core/Json/ApiKeysSerializerContext.cs
deleted file mode 100644
index 37d5f295..00000000
--- a/src/DragonFly.ApiKeys.Core/Json/ApiKeysSerializerContext.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (c) usercode
-// https://github.com/usercode/DragonFly
-// MIT License
-
-using System.Collections.Generic;
-using System.Text.Json;
-using System.Text.Json.Serialization;
-
-namespace DragonFly.ApiKeys;
-
-//Models
-[JsonSerializable(typeof(ApiKey))]
-[JsonSerializable(typeof(IEnumerable))]
-
-//Defaults
-[JsonSourceGenerationOptions(JsonSerializerDefaults.Web)]
-public partial class ApiKeysSerializerContext : JsonSerializerContext
-{
-}
diff --git a/src/DragonFly.ApiKeys/DragonFlyBuilderExtensions.cs b/src/DragonFly.ApiKeys/DragonFlyBuilderExtensions.cs
index a8fc5b88..90265f52 100644
--- a/src/DragonFly.ApiKeys/DragonFlyBuilderExtensions.cs
+++ b/src/DragonFly.ApiKeys/DragonFlyBuilderExtensions.cs
@@ -18,8 +18,6 @@ public static class DragonFlyBuilderExtensions
{
public static IDragonFlyBuilder AddApiKeys(this IDragonFlyBuilder builder)
{
- builder.AddRestSerializerResolver(ApiKeysSerializerContext.Default);
-
builder.Services.AddTransient();
builder.Services.AddSingleton();
diff --git a/src/DragonFly.Core/Extensions/DragonFlyBuilderExtensions.cs b/src/DragonFly.Core/Extensions/DragonFlyBuilderExtensions.cs
index 6e2e64c6..e5a7e233 100644
--- a/src/DragonFly.Core/Extensions/DragonFlyBuilderExtensions.cs
+++ b/src/DragonFly.Core/Extensions/DragonFlyBuilderExtensions.cs
@@ -53,12 +53,4 @@ public static IDragonFlyBuilder AddDragonFlyCore(this IServiceCollection service
return new DragonFlyBuilder(services)
.AddCore();
}
-
- public static TDragonFlyBuilder AddBlockFieldSerializerResolver(this TDragonFlyBuilder builder, IJsonTypeInfoResolver resolver)
- where TDragonFlyBuilder : IDragonFlyBuilder
- {
- BlockFieldSerializer.Options.TypeInfoResolverChain.Add(resolver);
-
- return builder;
- }
}
diff --git a/src/DragonFly.Core/Json/BlockFieldSerializerContext.cs b/src/DragonFly.Core/Json/BlockFieldSerializerContext.cs
deleted file mode 100644
index d3a5a73b..00000000
--- a/src/DragonFly.Core/Json/BlockFieldSerializerContext.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (c) usercode
-// https://github.com/usercode/DragonFly
-// MIT License
-
-using System.Text.Json;
-using System.Text.Json.Serialization;
-
-namespace DragonFly;
-
-[JsonSerializable(typeof(Document))]
-
-//Blocks
-[JsonSerializable(typeof(IEnumerable))]
-
-[JsonSerializable(typeof(AlertBlock))]
-[JsonSerializable(typeof(AssetBlock))]
-[JsonSerializable(typeof(CardsBlock))]
-[JsonSerializable(typeof(CodeBlock))]
-[JsonSerializable(typeof(ContainerBlock))]
-[JsonSerializable(typeof(ColumnBlock))]
-[JsonSerializable(typeof(GridBlock))]
-[JsonSerializable(typeof(HeadingBlock))]
-[JsonSerializable(typeof(HtmlBlock))]
-[JsonSerializable(typeof(OpenGraphBlock))]
-[JsonSerializable(typeof(ProgressBlock))]
-[JsonSerializable(typeof(QuoteBlock))]
-[JsonSerializable(typeof(ReferenceBlock))]
-[JsonSerializable(typeof(SectionBlock))]
-[JsonSerializable(typeof(SlideshowBlock))]
-[JsonSerializable(typeof(TextBlock))]
-[JsonSerializable(typeof(YouTubeBlock))]
-
-//defaults
-[JsonSourceGenerationOptions(JsonSerializerDefaults.Web)]
-internal partial class BlockFieldSerializerContext : JsonSerializerContext
-{
-
-}
diff --git a/src/DragonFly.Core/Json/BlockFieldSerializerResolver.cs b/src/DragonFly.Core/Json/BlockFieldSerializerResolver.cs
deleted file mode 100644
index 10170b1e..00000000
--- a/src/DragonFly.Core/Json/BlockFieldSerializerResolver.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (c) usercode
-// https://github.com/usercode/DragonFly
-// MIT License
-
-using System.Text.Json;
-using System.Text.Json.Serialization.Metadata;
-
-namespace DragonFly;
-
-internal class BlockFieldSerializerResolver : IJsonTypeInfoResolver
-{
- public static BlockFieldSerializerResolver Default { get; } = new BlockFieldSerializerResolver();
-
- private BlockFieldSerializerResolver()
- {
- }
-
- public JsonTypeInfo? GetTypeInfo(Type type, JsonSerializerOptions options)
- {
- JsonTypeInfo? jsonTypeInfo = ((IJsonTypeInfoResolver)BlockFieldSerializerContext.Default).GetTypeInfo(type, options);
-
- if (jsonTypeInfo != null)
- {
- if (jsonTypeInfo.Type == typeof(Block))
- {
- JsonPolymorphismOptions optionsDerivedTypes = new JsonPolymorphismOptions() { TypeDiscriminatorPropertyName = "Type" };
-
- foreach (BlockFactory blockFactory in BlockManager.Default.GetAllBlocks())
- {
- optionsDerivedTypes.DerivedTypes.Add(new JsonDerivedType(blockFactory.BlockType, blockFactory.BlockName));
- }
-
- jsonTypeInfo.PolymorphismOptions = optionsDerivedTypes;
- }
- }
-
- return jsonTypeInfo;
- }
-}
diff --git a/src/DragonFly.Core/Extensions/Css/BootstrapExtensions.cs b/src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Css/BootstrapExtensions.cs
similarity index 100%
rename from src/DragonFly.Core/Extensions/Css/BootstrapExtensions.cs
rename to src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Css/BootstrapExtensions.cs
diff --git a/src/DragonFly.Core/Extensions/Css/CssExtensions.cs b/src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Css/CssExtensions.cs
similarity index 100%
rename from src/DragonFly.Core/Extensions/Css/CssExtensions.cs
rename to src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Css/CssExtensions.cs
diff --git a/src/DragonFly.Core/Extensions/Css/PrismExtensions.cs b/src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Css/PrismExtensions.cs
similarity index 100%
rename from src/DragonFly.Core/Extensions/Css/PrismExtensions.cs
rename to src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Css/PrismExtensions.cs
diff --git a/src/DragonFly.Core/Json/BlockFieldSerializer.cs b/src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/BlockFieldSerializer.cs
similarity index 100%
rename from src/DragonFly.Core/Json/BlockFieldSerializer.cs
rename to src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/BlockFieldSerializer.cs
diff --git a/src/DragonFly.Core/Json/BlockFieldSerializerExtensions.cs b/src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/BlockFieldSerializerExtensions.cs
similarity index 100%
rename from src/DragonFly.Core/Json/BlockFieldSerializerExtensions.cs
rename to src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/BlockFieldSerializerExtensions.cs
diff --git a/src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/BlockFieldSerializerResolver.cs b/src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/BlockFieldSerializerResolver.cs
new file mode 100644
index 00000000..a4d7c4bd
--- /dev/null
+++ b/src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/BlockFieldSerializerResolver.cs
@@ -0,0 +1,36 @@
+// Copyright (c) usercode
+// https://github.com/usercode/DragonFly
+// MIT License
+
+using System.Text.Json;
+using System.Text.Json.Serialization.Metadata;
+
+namespace DragonFly;
+
+internal class BlockFieldSerializerResolver : DefaultJsonTypeInfoResolver
+{
+ public static BlockFieldSerializerResolver Default { get; } = new BlockFieldSerializerResolver();
+
+ private BlockFieldSerializerResolver()
+ {
+ }
+
+ public override JsonTypeInfo GetTypeInfo(Type type, JsonSerializerOptions options)
+ {
+ JsonTypeInfo jsonTypeInfo = base.GetTypeInfo(type, options);
+
+ if (jsonTypeInfo.Type == typeof(Block))
+ {
+ JsonPolymorphismOptions optionsDerivedTypes = new JsonPolymorphismOptions() { TypeDiscriminatorPropertyName = "Type" };
+
+ foreach (BlockFactory blockFactory in BlockManager.Default.GetAllBlocks())
+ {
+ optionsDerivedTypes.DerivedTypes.Add(new JsonDerivedType(blockFactory.BlockType, blockFactory.BlockName));
+ }
+
+ jsonTypeInfo.PolymorphismOptions = optionsDerivedTypes;
+ }
+
+ return jsonTypeInfo;
+ }
+}
diff --git a/src/DragonFly.Core/Json/Serializers/BlockFieldConverter.cs b/src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/Serializers/BlockFieldConverter.cs
similarity index 100%
rename from src/DragonFly.Core/Json/Serializers/BlockFieldConverter.cs
rename to src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/Serializers/BlockFieldConverter.cs
diff --git a/src/DragonFly.Core/Json/Serializers/BlockFieldSerializerV0.cs b/src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/Serializers/BlockFieldSerializerV0.cs
similarity index 100%
rename from src/DragonFly.Core/Json/Serializers/BlockFieldSerializerV0.cs
rename to src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/Serializers/BlockFieldSerializerV0.cs
diff --git a/src/DragonFly.Core/Json/Serializers/BlockFieldSerializerV1.cs b/src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/Serializers/BlockFieldSerializerV1.cs
similarity index 100%
rename from src/DragonFly.Core/Json/Serializers/BlockFieldSerializerV1.cs
rename to src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/Serializers/BlockFieldSerializerV1.cs
diff --git a/src/DragonFly.Core/Json/Serializers/Converters/EnumStringJsonConverterFactory.cs b/src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/Serializers/Converters/EnumStringJsonConverterFactory.cs
similarity index 100%
rename from src/DragonFly.Core/Json/Serializers/Converters/EnumStringJsonConverterFactory.cs
rename to src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/Serializers/Converters/EnumStringJsonConverterFactory.cs
diff --git a/src/DragonFly.Core/Json/Serializers/Converters/EnumToStringConverter.cs b/src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/Serializers/Converters/EnumToStringConverter.cs
similarity index 100%
rename from src/DragonFly.Core/Json/Serializers/Converters/EnumToStringConverter.cs
rename to src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/Serializers/Converters/EnumToStringConverter.cs
diff --git a/src/DragonFly.Core/Json/Serializers/Converters/NullableEnumToStringConverter.cs b/src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/Serializers/Converters/NullableEnumToStringConverter.cs
similarity index 100%
rename from src/DragonFly.Core/Json/Serializers/Converters/NullableEnumToStringConverter.cs
rename to src/DragonFly.Core/Modules/ContentItems/Models/Fields/BlockField/Json/Serializers/Converters/NullableEnumToStringConverter.cs
diff --git a/src/DragonFly.Identity.Client/Extensions/DragonFlyBuilderIdentityExtensions.cs b/src/DragonFly.Identity.Client/Extensions/DragonFlyBuilderIdentityExtensions.cs
index dfdf6648..34246e4d 100644
--- a/src/DragonFly.Identity.Client/Extensions/DragonFlyBuilderIdentityExtensions.cs
+++ b/src/DragonFly.Identity.Client/Extensions/DragonFlyBuilderIdentityExtensions.cs
@@ -20,7 +20,6 @@ public static class DragonFlyBuilderIdentityExtensions
public static IDragonFlyBuilder AddIdentity(this IDragonFlyBuilder builder)
{
builder.AddRazorRouting();
- builder.AddRestSerializerResolver(IdentitySerializerContext.Default);
builder.Services.AddTransient();
builder.Services.AddTransient();
diff --git a/src/DragonFly.Identity.Client/Services/IdentityService.cs b/src/DragonFly.Identity.Client/Services/IdentityService.cs
index 2f533c15..25427f56 100644
--- a/src/DragonFly.Identity.Client/Services/IdentityService.cs
+++ b/src/DragonFly.Identity.Client/Services/IdentityService.cs
@@ -2,6 +2,7 @@
// https://github.com/usercode/DragonFly
// MIT License
+using DragonFly.API;
using DragonFly.Identity.Commands;
using DragonFly.Identity.Rest.Commands;
using DragonFly.Identity.Services;
@@ -33,7 +34,7 @@ public async Task ChangePasswordAsync(Guid id, string newPassword)
public async Task CreateRoleAsync(IdentityRole role)
{
- HttpResponseMessage response = await Client.PostAsJsonAsync("api/identity/role", role, IdentitySerializerContext.Default.IdentityRole);
+ HttpResponseMessage response = await Client.PostAsJsonAsync("api/identity/role", role, ApiJsonSerializerDefault.Options);
response.EnsureSuccessStatusCode();
}
@@ -44,7 +45,7 @@ public async Task CreateUserAsync(IdentityUser user, string password)
createUser.User = user;
createUser.Password = password;
- HttpResponseMessage response = await Client.PostAsJsonAsync("api/identity/user", createUser, IdentitySerializerContext.Default.CreateUser);
+ HttpResponseMessage response = await Client.PostAsJsonAsync("api/identity/user", createUser, ApiJsonSerializerDefault.Options);
response.EnsureSuccessStatusCode();
}
@@ -53,7 +54,7 @@ public async Task> GetRolesAsync()
{
HttpResponseMessage response = await Client.PostAsync($"api/identity/role/query", new StringContent(""));
- IEnumerable? result = await response.Content.ReadFromJsonAsync(IdentitySerializerContext.Default.IEnumerableIdentityRole);
+ IEnumerable? result = await response.Content.ReadFromJsonAsync>(ApiJsonSerializerDefault.Options);
if (result == null)
{
@@ -67,7 +68,7 @@ public async Task> GetUsersAsync()
{
HttpResponseMessage response = await Client.PostAsync($"api/identity/user/query", new StringContent(""));
- IEnumerable? result = await response.Content.ReadFromJsonAsync(IdentitySerializerContext.Default.IEnumerableIdentityUser);
+ IEnumerable? result = await response.Content.ReadFromJsonAsync>(ApiJsonSerializerDefault.Options);
if (result == null)
{
@@ -79,7 +80,7 @@ public async Task> GetUsersAsync()
public async Task GetUserAsync(string username)
{
- IdentityUser? user = await Client.GetFromJsonAsync($"api/identity/user/{username}", IdentitySerializerContext.Default.IdentityUser);
+ IdentityUser? user = await Client.GetFromJsonAsync($"api/identity/user/{username}", ApiJsonSerializerDefault.Options);
if (user == null)
{
@@ -91,7 +92,7 @@ public async Task GetUserAsync(string username)
public async Task GetUserAsync(Guid id)
{
- IdentityUser? user = await Client.GetFromJsonAsync($"api/identity/user/{id}", IdentitySerializerContext.Default.IdentityUser);
+ IdentityUser? user = await Client.GetFromJsonAsync($"api/identity/user/{id}", ApiJsonSerializerDefault.Options);
if (user == null)
{
@@ -103,21 +104,21 @@ public async Task GetUserAsync(Guid id)
public async Task UpdateUserAsync(IdentityUser user)
{
- HttpResponseMessage response = await Client.PutAsJsonAsync("api/identity/user", user, IdentitySerializerContext.Default.IdentityUser);
+ HttpResponseMessage response = await Client.PutAsJsonAsync("api/identity/user", user, ApiJsonSerializerDefault.Options);
response.EnsureSuccessStatusCode();
}
public async Task UpdateRoleAsync(IdentityRole role)
{
- HttpResponseMessage response = await Client.PutAsJsonAsync("api/identity/role", role, IdentitySerializerContext.Default.IdentityRole);
+ HttpResponseMessage response = await Client.PutAsJsonAsync("api/identity/role", role, ApiJsonSerializerDefault.Options);
response.EnsureSuccessStatusCode();
}
public async Task GetRoleAsync(Guid id)
{
- IdentityRole? role = await Client.GetFromJsonAsync($"api/identity/role/{id}", IdentitySerializerContext.Default.IdentityRole);
+ IdentityRole? role = await Client.GetFromJsonAsync($"api/identity/role/{id}", ApiJsonSerializerDefault.Options);
if (role == null)
{
diff --git a/src/DragonFly.Identity.Core/Json/IdentitySerializerContext.cs b/src/DragonFly.Identity.Core/Json/IdentitySerializerContext.cs
deleted file mode 100644
index 98c9816d..00000000
--- a/src/DragonFly.Identity.Core/Json/IdentitySerializerContext.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (c) usercode
-// https://github.com/usercode/DragonFly
-// MIT License
-
-using System.Text.Json;
-using System.Text.Json.Serialization;
-using DragonFly.AspNetCore.Exports;
-using DragonFly.Identity.Commands;
-using DragonFly.Identity.Rest.Commands;
-
-namespace DragonFly.Identity;
-
-//Models
-[JsonSerializable(typeof(IdentityUser))]
-[JsonSerializable(typeof(IdentityRole))]
-[JsonSerializable(typeof(IEnumerable))]
-[JsonSerializable(typeof(IEnumerable))]
-[JsonSerializable(typeof(IEnumerable))]
-
-//Actions
-[JsonSerializable(typeof(LoginData))]
-[JsonSerializable(typeof(ChangePassword))]
-[JsonSerializable(typeof(CreateUser))]
-
-//Defaults
-[JsonSourceGenerationOptions(JsonSerializerDefaults.Web)]
-public partial class IdentitySerializerContext : JsonSerializerContext
-{
-}
diff --git a/src/DragonFly.Identity/DragonFlyBuilderExtensions.cs b/src/DragonFly.Identity/DragonFlyBuilderExtensions.cs
index 85ec2779..9dcc8b16 100644
--- a/src/DragonFly.Identity/DragonFlyBuilderExtensions.cs
+++ b/src/DragonFly.Identity/DragonFlyBuilderExtensions.cs
@@ -22,8 +22,6 @@ public static class DragonFlyBuilderExtensions
{
public static IDragonFlyBuilder AddMongoDbIdentity(this IDragonFlyBuilder builder)
{
- builder.AddRestSerializerResolver(IdentitySerializerContext.Default);
-
builder.Services.AddTransient();
builder.Services.AddTransient();