How to use [JsonIgnore] attributes on a service in a u10 site
I have of API endpoints in my project. They typically use a model like this:
using Newtonsoft.Json;
public class MyModel
{
[JsonIgnore]
public int NodeId { get; set; }
[JsonProperty(PropertyName = "title")]
public string Name { get; set; }
public string Reference { get; set; }
}
And a controller like this:
[ApiController]
[Route("api/my-endpoint")]
public sealed class MyEndpointApiController : Controller
{
[HttpGet]
[Route("all")]
[ProducesResponseType(typeof(List<MyModel>), StatusCodes.Status200OK)]
public ActionResult GetAllHTQualifications()
{
List<MyModel> models = GetAll<MyModel>();
return Ok(models);
}
}
This request returns a response, but the NodeId is still there in the data and Name has not been changed to title. Is there something I need to do to force it to use the NewtonSoft attributes or should I be changing over to the .Net Core serialisation attributes instead? I have tried using those and they don't seem to work either. What do I need to do to get my Json objects serialised in a way that respects their attributes?
How to use [JsonIgnore] attributes on a service in a u10 site
I have of API endpoints in my project. They typically use a model like this:
And a controller like this:
This request returns a response, but the
NodeId
is still there in the data andName
has not been changed totitle
. Is there something I need to do to force it to use the NewtonSoft attributes or should I be changing over to the .Net Core serialisation attributes instead? I have tried using those and they don't seem to work either. What do I need to do to get my Json objects serialised in a way that respects their attributes?is working on a reply...