mirror of https://github.com/abpframework/abp.git
8 changed files with 28 additions and 143 deletions
@ -1,44 +0,0 @@ |
|||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.Text.Json; |
|
||||
using System.Text.Json.Serialization; |
|
||||
using Volo.Abp.AspNetCore.Mvc.Dapr.EventBus.Models; |
|
||||
using Volo.Abp.Dapr; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Mvc.Dapr.EventBus.Json; |
|
||||
|
|
||||
public class AbpDaprSubscriptionRequestConverter<T> : JsonConverter<AbpDaprSubscriptionRequest<T>> |
|
||||
where T : class |
|
||||
{ |
|
||||
private JsonSerializerOptions _readJsonSerializerOptions; |
|
||||
|
|
||||
private readonly IDaprSerializer _daprSerializer; |
|
||||
|
|
||||
public AbpDaprSubscriptionRequestConverter(IDaprSerializer daprSerializer) |
|
||||
{ |
|
||||
_daprSerializer = daprSerializer; |
|
||||
} |
|
||||
|
|
||||
public override AbpDaprSubscriptionRequest<T> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
|
||||
{ |
|
||||
_readJsonSerializerOptions ??= CreateJsonSerializerOptions(options); |
|
||||
|
|
||||
var rootElement = JsonDocument.ParseValue(ref reader).RootElement; |
|
||||
var obj = JsonSerializer.Deserialize<AbpDaprSubscriptionRequest<T>>(rootElement.GetRawText(), _readJsonSerializerOptions); |
|
||||
obj.Data = _daprSerializer.Deserialize(rootElement.GetProperty("data").GetRawText(), typeof(T)).As<T>(); |
|
||||
return obj; |
|
||||
} |
|
||||
|
|
||||
public override void Write(Utf8JsonWriter writer, AbpDaprSubscriptionRequest<T> value, JsonSerializerOptions options) |
|
||||
{ |
|
||||
throw new NotSupportedException(); |
|
||||
} |
|
||||
|
|
||||
private JsonSerializerOptions CreateJsonSerializerOptions(JsonSerializerOptions options) |
|
||||
{ |
|
||||
var newOptions = new JsonSerializerOptions(options); |
|
||||
newOptions.Converters.RemoveAll(x => x == this || x.GetType() == typeof(AbpDaprSubscriptionRequestConverterFactory)); |
|
||||
newOptions.PropertyNamingPolicy = new AbpDaprSubscriptionRequestJsonNamingPolicy(); |
|
||||
return newOptions; |
|
||||
} |
|
||||
} |
|
||||
@ -1,33 +0,0 @@ |
|||||
using System; |
|
||||
using System.Reflection; |
|
||||
using System.Text.Json; |
|
||||
using System.Text.Json.Serialization; |
|
||||
using Volo.Abp.AspNetCore.Mvc.Dapr.EventBus.Models; |
|
||||
using Volo.Abp.Dapr; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Mvc.Dapr.EventBus.Json; |
|
||||
|
|
||||
public class AbpDaprSubscriptionRequestConverterFactory : JsonConverterFactory |
|
||||
{ |
|
||||
private readonly IDaprSerializer _daprSerializer; |
|
||||
|
|
||||
public AbpDaprSubscriptionRequestConverterFactory(IDaprSerializer daprSerializer) |
|
||||
{ |
|
||||
_daprSerializer = daprSerializer; |
|
||||
} |
|
||||
|
|
||||
public override bool CanConvert(Type typeToConvert) |
|
||||
{ |
|
||||
return typeToConvert.GetGenericTypeDefinition() == typeof(AbpDaprSubscriptionRequest<>); |
|
||||
} |
|
||||
|
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) |
|
||||
{ |
|
||||
return (JsonConverter)Activator.CreateInstance( |
|
||||
typeof(AbpDaprSubscriptionRequestConverter<>).MakeGenericType(typeToConvert.GetGenericArguments()[0]), |
|
||||
BindingFlags.Instance | BindingFlags.Public, |
|
||||
binder: null, |
|
||||
new object[] { _daprSerializer }, |
|
||||
culture: null)!; |
|
||||
} |
|
||||
} |
|
||||
@ -1,11 +0,0 @@ |
|||||
using System.Text.Json; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Mvc.Dapr.EventBus.Json; |
|
||||
|
|
||||
public class AbpDaprSubscriptionRequestJsonNamingPolicy : JsonNamingPolicy |
|
||||
{ |
|
||||
public override string ConvertName(string name) |
|
||||
{ |
|
||||
return name.ToLower(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,11 +0,0 @@ |
|||||
namespace Volo.Abp.AspNetCore.Mvc.Dapr.EventBus.Models; |
|
||||
|
|
||||
public class AbpDaprSubscriptionRequest<T> |
|
||||
where T : class |
|
||||
{ |
|
||||
public string PubSubName { get; set; } |
|
||||
|
|
||||
public string Topic { get; set; } |
|
||||
|
|
||||
public T Data { get; set; } |
|
||||
} |
|
||||
Loading…
Reference in new issue