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

 

作者:陈哲Gilbert
出处:http://gilbert.cnblogs.com
版权声明:
本文版权归作者所有,欢迎转载,请在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。

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