hi
I will enhance this in the abp framework.
context.Services.Configure<JsonOptions>(options =>
{
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
options.JsonSerializerOptions.Converters.RemoveAll(x => x is AbpStringToEnumFactory);
options.JsonSerializerOptions.Converters.Add(new MyAbpStringToEnumFactory());
});
using System;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
using Volo.Abp.Json.SystemTextJson.JsonConverters;
namespace Acme.BookStore;
public class MyAbpStringToEnumFactory : JsonConverterFactory
{
private readonly JsonNamingPolicy? _namingPolicy;
private readonly bool _allowIntegerValues;
public MyAbpStringToEnumFactory()
: this(namingPolicy: null, allowIntegerValues: true)
{
}
public MyAbpStringToEnumFactory(JsonNamingPolicy? namingPolicy, bool allowIntegerValues)
{
_namingPolicy = namingPolicy;
_allowIntegerValues = allowIntegerValues;
}
public override bool CanConvert(Type typeToConvert)
{
return typeToConvert.IsEnum;
}
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
{
return (JsonConverter)Activator.CreateInstance(
typeof(MyAbpStringToEnumConverter<>).MakeGenericType(typeToConvert),
BindingFlags.Instance | BindingFlags.Public,
binder: null,
new object?[] { _namingPolicy, _allowIntegerValues },
culture: null)!;
}
}
public class MyAbpStringToEnumConverter<T> : JsonConverter<T>
where T : struct, Enum
{
private readonly JsonStringEnumConverter _innerJsonStringEnumConverter;
private JsonSerializerOptions? _readJsonSerializerOptions;
private JsonSerializerOptions? _writeJsonSerializerOptions;
public MyAbpStringToEnumConverter()
: this(namingPolicy: null, allowIntegerValues: true)
{
}
public MyAbpStringToEnumConverter(JsonNamingPolicy? namingPolicy = null, bool allowIntegerValues = true)
{
_innerJsonStringEnumConverter = new JsonStringEnumConverter(namingPolicy, allowIntegerValues);
}
public override bool CanConvert(Type typeToConvert)
{
return typeToConvert.IsEnum;
}
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
_readJsonSerializerOptions ??= JsonSerializerOptionsHelper.Create(options, x =>
x == this ||
x.GetType() == typeof(AbpStringToEnumFactory),
_innerJsonStringEnumConverter.CreateConverter(typeToConvert, options));
return JsonSerializer.Deserialize<T>(ref reader, _readJsonSerializerOptions);
}
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
{
_writeJsonSerializerOptions ??= JsonSerializerOptionsHelper.Create(options, x =>
x == this ||
x.GetType() == typeof(MyAbpStringToEnumFactory),
_innerJsonStringEnumConverter.CreateConverter(typeof(T), options));
JsonSerializer.Serialize(writer, value,_writeJsonSerializerOptions);
}
public override T ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return (T)Enum.Parse(typeToConvert, reader.GetString()!);
}
public override void WriteAsPropertyName(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
{
writer.WritePropertyName(Enum.GetName(typeof(T), value)!);
}
}
Thanks. I will run and test your project.
hi
Steps or project to reproduce the issue, Thanks.
hi
Please share a test project with me, I will debug it. Thanks
liming.ma@volosoft.com
hi
It seems the user.Claims is null
hi
You can set a random GUID to SecurityStamp
You can encrypt the password for PasswordHash
//IPasswordHasher<IdentityUser>
PasswordHash = PasswordHasher.HashPassword(user, PlainPasswordText);
hi
Can you reproduce it in a new template module and app projects?
Remote checking/debugging is slow.
Thanks.
hi dipak.z
I know your problem, I need to reproduce the problem in my local environment and troubleshoot the cause.
hi
You can add PermissionManagement module as a reference to your module, add depends on it modules and inject the IPermissionManager