Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported
I am trying to store object that has
public class AuthInfo
{
public string AuthToken { get; set; }
public string FristName { get; set; }
public string LastName { get; set; }
public string DisplayName { get; set; }
public string Email { get; set; }
public string CountryDialingCode { get; set; }
public string TelePhone { get; set; }
public List<Claim> Claims { get; set; }
}
await _localStorage.SetItemAsync<AuthInfo>("AuthInfo",authInfo);
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type 'System.Security.Claims.Claim'. Path: $.Claims[0] | LineNumber: 9 | BytePositionInLine: 5.
Do i have option to instead use newtonsoft for serialization & deserialization ?
I used the suggestion from this post and now using json.net since it provide the capability to write custom convert.
https://stackoverflow.com/questions/28155169/how-to-programmatically-choose-a-constructor-during-deserialization
Hi @nssidh,
The JSON serialiser is replaceable. See the server sample project for an example where it has been replaced with a Newtonsoft JSON one (samples/BlazorServer/Program.cs)
builder.Services.Replace(ServiceDescriptor.Scoped<IJsonSerializer, NewtonSoftJsonSerializer>()); This one replaces for the whole application.
Is there one just for your Blazored Component ( and that too may be temporarily for such odd objects and then revert back to default one) ?
This is for Blazored LocalStorage. The IJsonSerializer interface is from this library.
Closing as there is nothing else to do.