Unable to find a constructor to use for type System.Security.Claims.Claim. A class should either have a default constructor

时间:2023-03-09 19:33:22
Unable to find a constructor to use for type System.Security.Claims.Claim. A class should either have a default constructor

Newtonsoft.Json DeserializeObject 反序列化  IdentityServer4.Models Cliecnt

错误:

Newtonsoft.Json.JsonSerializationException:

Unable to find a constructor to use for type System.Security.Claims.Claim. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'clients[0].Claims[0].Issuer', line 1, position 5373.
JsonConvert.DeserializeObject<T>(value);
//会抛出Newtonsoft.Json.JsonSerializationException异常 //解决方案:
JsonConvert.DeserializeObject<T>(value, new IdentityServer4.Stores.Serialization.ClaimConverter());

在IdentityServer4中,已经对System.Security.Claims.Claim做了处理。

使用IdentityServer4.Stores.Serialization.ClaimConverter()即可

在*上有解决方案重载JsonConverter后写了ClaimConverter

详细请查看https://*.com/questions/28155169/how-to-programmatically-choose-a-constructor-during-deserialization