public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var source = (ClaimsPrincipal)value; var target = new ClaimsPrincipalLite { AuthenticationType = source.Identity.AuthenticationType, Claims = source.Claims.Select(x => new ClaimLite { Type = x.Type, Value = x.Value, ValueType = x.ValueType }).ToArray() }; serializer.Serialize(writer, target); }
public override void Write(Utf8JsonWriter writer, ClaimsPrincipal value, JsonSerializerOptions options) { var target = new ClaimsPrincipalLite { AuthenticationType = value.Identity.AuthenticationType, Claims = value.Claims.Select(x => { var cl = new ClaimLite { Type = x.Type, Value = x.Value, ValueType = x.ValueType }; if (cl.ValueType == ClaimValueTypes.String) { cl.ValueType = null; } return(cl); }).ToArray() }; JsonSerializer.Serialize(writer, target, options); }