I tried using the solution of encrypting some properties of my class in JSON mentioned by Thomas Freudenberg. When I serialize the object using JsonConvert.SerializeObject()
I get the desired result.
The class and convertor are located in a separate assembly, which is referenced in my WebAPI project. When I use the following:
[HttpPost]
[Route("api/ApiUsers/List")]
public Dto.ApiUsersResponse List(Dto.ApiUsersRequest apiUsersRequest)
{
IEnumerable<Db.ApiUser> dbApiUsers = GetList<Db.ApiUser>(StoredProcedures.GetApiUsers);
return new Dto.ApiUsersResponse()
{
ApiUsers = dbApiUsers.Select(apiUser => new Dto.ApiUser()
{
ClientId = apiUser.ClientId,
ClientSecret = apiUser.ClientSecret
})
};
}
the result is in clear text instead. The conversion never happens.
I have tried changing the controller's response IHttpActionResult and using Ok()
and Content()
but to no avail.
When I try to register the convertor using:
config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new EncryptingJsonConverter());
The error is:
Cannot resolve symbol 'JsonFormatter'
What am I missing?