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()即可

 

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

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

 

posted @ 2019-02-12 16:19  陈哲Gilbert  阅读(2701)  评论(0编辑  收藏  举报