Skip to content

JsonIgnore with condition incorrectly ignoring property when using OData $select query with [EnableQuery] endpoint #2825

Open
@radderz

Description

@radderz
public class MyClass
{
	public Guid Id { get; set; }

	[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
	public Guid? SomeReferenceId { get; set; }
}

When using a class like above, on a standard ASP.NET Core controller like below:

[Route("api/[controller]")]
[ApiController]
public class MyClassController : Controller
{
	[HttpGet]
	[EnableQuery]
	public List<MyClass> GetAll()
	{
		return new List<MyClass>
		{
			new MyClass
			{
				Id = Guid.NewGuid()
			},
			new MyClass
			{
				Id = Guid.NewGuid(),
				SomeReferenceId = Guid.NewGuid()
			},
		}
	}
}

Doing a query like /api/MyClass?$select=someReferenceId will return an array of blank objects instead of 1 blank object and one with the someReferenceId.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions