I'm having trouble serializing JSON text to an object that contains a SecureString variable. How might I serialize the following whilst keeping the public 'pwd' variable a SecureString?
Let's say have the following string:
string j_str = "{ 'uid':'JohnDoe', 'age':30, 'pwd':'MyPassword' }";
and I would like to serialize this string into an object I have in C#
public class User
{
public string uid = { get; set; }
public string age = { get; set; }
public SecureString pwd = { get; set; }
}
So I may the following call using the JSON ToObject) call with Newtonsoft like so:
JObject j_obj = JObject.Parse(j_str);
User newUser = j_obj.ToObject<User>();
This results in the following error:
Newtonsoft.Json.JsonSerializationException: 'Error converting value "MyPassword" to type 'System.Security.SecureString'. Path 'pwd'