Skip to content

Commit

Permalink
Removed JsonSerializerContext
Browse files Browse the repository at this point in the history
  • Loading branch information
usercode committed Mar 19, 2024
1 parent 00ae0d2 commit d3990eb
Show file tree
Hide file tree
Showing 29 changed files with 73 additions and 308 deletions.
9 changes: 1 addition & 8 deletions src/DragonFly.API.Core/Assets/RestAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ namespace DragonFly.API;
/// </summary>
public class RestAsset : RestContentBase
{
public RestAsset()
{
_metaddata = new JsonObject();
}

/// <summary>
/// Name
/// </summary>
Expand Down Expand Up @@ -61,10 +56,8 @@ public RestAsset()
/// </summary>
public virtual RestAssetFolder Folder { get; set; }

private JsonObject _metaddata;

/// <summary>
/// Metaddata
/// </summary>
public virtual JsonObject Metaddata { get => _metaddata; set => _metaddata = value; }
public virtual JsonObject Metaddata { get; set; } = new JsonObject();
}
7 changes: 1 addition & 6 deletions src/DragonFly.API.Core/ContentItems/RestContentItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ namespace DragonFly.API;
/// </summary>
public class RestContentItem : RestContentBase
{
public RestContentItem()
{
Fields = new JsonObject();
}

/// <summary>
/// Schema
/// </summary>
Expand All @@ -41,6 +36,6 @@ public RestContentItem()
/// </summary>
[JsonPropertyOrder(30)]
//[JsonConverter(typeof(MyConverter))]
public JsonObject Fields { get; set; }
public JsonObject Fields { get; set; } = new JsonObject();

}
26 changes: 0 additions & 26 deletions src/DragonFly.API.Core/Extensions/DragonFlyBuilderExtensions.cs

This file was deleted.

93 changes: 0 additions & 93 deletions src/DragonFly.API.Core/Json/ApiJsonSerializerContext.cs

This file was deleted.

39 changes: 18 additions & 21 deletions src/DragonFly.API.Core/Json/ApiJsonTypeInfoResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace DragonFly.API;

public class ApiJsonTypeInfoResolver : IJsonTypeInfoResolver
public class ApiJsonTypeInfoResolver : DefaultJsonTypeInfoResolver
{
/// <summary>
/// Default
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RestAsset>(ApiJsonSerializerDefault.Options);

if (restAsset != null)
{
Expand All @@ -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
{
Expand Down
1 change: 0 additions & 1 deletion src/DragonFly.ApiKeys.Client/DragonFlyBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public static class DragonFlyBuilderExtensions
public static IDragonFlyBuilder AddApiKeys(this IDragonFlyBuilder builder)
{
builder.AddRazorRouting();
builder.AddRestSerializerResolver(ApiKeysSerializerContext.Default);

builder.Services.AddTransient<IApiKeyService, ApiKeyService>();

Expand Down
9 changes: 5 additions & 4 deletions src/DragonFly.ApiKeys.Client/Services/ApiKeyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
}
Expand All @@ -49,7 +50,7 @@ public async Task<IEnumerable<ApiKey>> QueryApiKeys()

response.EnsureSuccessStatusCode();

IEnumerable<ApiKey>? result = await response.Content.ReadFromJsonAsync(ApiKeysSerializerContext.Default.IEnumerableApiKey);
IEnumerable<ApiKey>? result = await response.Content.ReadFromJsonAsync<IEnumerable<ApiKey>>(ApiJsonSerializerDefault.Options);

if (result == null)
{
Expand All @@ -66,7 +67,7 @@ public Task<ApiKey> GetApiKey(string value)

public async Task<ApiKey> GetApiKey(Guid id)
{
ApiKey? apikey = await Client.GetFromJsonAsync($"api/apikey/{id}", ApiKeysSerializerContext.Default.ApiKey);
ApiKey? apikey = await Client.GetFromJsonAsync<ApiKey>($"api/apikey/{id}", ApiJsonSerializerDefault.Options);

if (apikey == null)
{
Expand Down
19 changes: 0 additions & 19 deletions src/DragonFly.ApiKeys.Core/Json/ApiKeysSerializerContext.cs

This file was deleted.

2 changes: 0 additions & 2 deletions src/DragonFly.ApiKeys/DragonFlyBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public static class DragonFlyBuilderExtensions
{
public static IDragonFlyBuilder AddApiKeys(this IDragonFlyBuilder builder)
{
builder.AddRestSerializerResolver(ApiKeysSerializerContext.Default);

builder.Services.AddTransient<IApiKeyService, ApiKeyService>();

builder.Services.AddSingleton<MongoIdentityStore>();
Expand Down
8 changes: 0 additions & 8 deletions src/DragonFly.Core/Extensions/DragonFlyBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,4 @@ public static IDragonFlyBuilder AddDragonFlyCore(this IServiceCollection service
return new DragonFlyBuilder(services)
.AddCore();
}

public static TDragonFlyBuilder AddBlockFieldSerializerResolver<TDragonFlyBuilder>(this TDragonFlyBuilder builder, IJsonTypeInfoResolver resolver)
where TDragonFlyBuilder : IDragonFlyBuilder
{
BlockFieldSerializer.Options.TypeInfoResolverChain.Add(resolver);

return builder;
}
}
38 changes: 0 additions & 38 deletions src/DragonFly.Core/Json/BlockFieldSerializerContext.cs

This file was deleted.

Loading

0 comments on commit d3990eb

Please sign in to comment.