Atividades de "daniil.poiarkov@happentechnologies.com"

Hi,

Yes, it is available when you extend the object, but the entity is difficult to do because of the database provider.

As we are using MongoDb we found a solution using same collection for entity, which inherits from build-in one, where we are able to easily expand it witout extension methods and have all necessary properties in one place. Hope it can be usefull if someone will have same problem

Hi,

You need to remove the AbpStringToEnumFactory

Just an example:

public class EnumToStringConverterFactory : JsonConverterFactory 
{ 
    public override bool CanConvert(Type typeToConvert) 
    { 
        return typeToConvert.IsEnum; 
    } 
 
    public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) 
    { 
        return (JsonConverter)Activator.CreateInstance( 
            typeof(MyEnumToStringConverter<>).MakeGenericType(typeToConvert), 
            BindingFlags.Instance | BindingFlags.Public, 
            binder: null, 
            new object?[] { }, 
            culture: null)!; 
    } 
} 
 
public class MyEnumToStringConverter<T> : JsonConverter<T> 
    where T : struct, Enum 
{ 
    public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 
    { 
        return Enum.Parse<T>(reader.GetString()!); 
    } 
 
    public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) 
    { 
        writer.WriteStringValue(value.ToString()); 
    } 
} 
 
Configure<AbpSystemTextJsonSerializerOptions>(options => 
{ 
    var stringToEnumFactory = options.JsonSerializerOptions.Converters.Single(x => x.GetType() == typeof(AbpStringToEnumFactory)); 
    options.JsonSerializerOptions.Converters.Remove(stringToEnumFactory); 
    options.JsonSerializerOptions.Converters.Add(new EnumToStringConverterFactory()); 
}); 
 
Configure<JsonOptions>(options => 
{ 
    var stringToEnumFactory = options.JsonSerializerOptions.Converters.Single(x => x.GetType() == typeof(AbpStringToEnumFactory)); 
    options.JsonSerializerOptions.Converters.Remove(stringToEnumFactory); 
    options.JsonSerializerOptions.Converters.Add(new EnumToStringConverterFactory()); 
}); 

Thanks a lot, removing AbpStringToEnumFactory solved my problem)

Hi,

Could you provide the full steps to reproduce the problem? I will check it. thanks

Sure,

  1. Configure Mvc.JsonOptions via Configure method (HttpApi.Host module)
  2. Dto
  3. Response

And this is how response look like with [JsonConvert(typeof(JsonStringEnumConverter))] attribute for SubscriptionType field

Our goal is to achive this without attribute specification

HI, Liangshiwei Yea, I tried to configure Mvc.JsonOptions as well, but still I need to use JsonConverter attribute. I'm wonder if it is possible to achieve this without specifying attribute on each enum property.

You can check this: https://github.com/abpframework/abp/issues/13010

Hi,

This is the limit of ExtraProperties, it only supports primitives.

Thank you very much for clarifying. I was confused that in docs it says that we can set and get it using non-generic method, but no info that we can't persist it

Mostrando 1 até 5 de 5 registros
Made with ❤️ on ABP v8.2.0-preview Updated on março 25, 2024, 15:11