0
vuvanquyet17102@gmail.com created
2 Answer(s)
-
0
The Extra properties serialised 'as-is'. if you want to return 'socialSecurityNumber' for a now you should write camelCase. I am looking the better solution. Maybe we will add Newtonsoft.Json.JsonProprertyAttribute support.
-
0
hi
Add the below code to your web project.
This may cause issues, because by design the key name in the dictionary is not camelCase
Configure<JsonOptions>(options => { options.JsonSerializerOptions.Converters.Add(new MyJsonConverter()); });
public class MyJsonConverter : JsonConverter<IdentityUserDto> { private JsonSerializerOptions _readJsonSerializerOptions; private JsonSerializerOptions _writeJsonSerializerOptions; public override IdentityUserDto Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { _readJsonSerializerOptions ??= new JsonSerializerOptions(options) { DictionaryKeyPolicy = JsonNamingPolicy.CamelCase }; _readJsonSerializerOptions.Converters.RemoveAll(x => x.GetType() == typeof(MyJsonConverter)); return JsonSerializer.Deserialize(ref reader, typeToConvert, _readJsonSerializerOptions).As<IdentityUserDto>(); } public override void Write(Utf8JsonWriter writer, IdentityUserDto value, JsonSerializerOptions options) { _writeJsonSerializerOptions ??= new JsonSerializerOptions(options) { DictionaryKeyPolicy = JsonNamingPolicy.CamelCase }; _writeJsonSerializerOptions.Converters.RemoveAll(x => x.GetType() == typeof(MyJsonConverter)); JsonSerializer.Serialize(writer, value, _writeJsonSerializerOptions); } }