Skip to content

Binder does not work when used with Newtonsoft.Json #61

Description

@Misiu

I've noticed that after adding HybridModelBinding to my project JsonProperty attributes stopped working.

Below is a very simple controller that allows testing this behaviour:

namespace HybridModelBinding.Samples.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class DataController : ControllerBase
    {
        [HttpPost()]
        public ActionResult<string> GetResCreateponse([FromHybrid]SimpleDto dto)
        {
            return Ok($"Hello {dto.Name} {dto.IsAdmin}");
        }
    }

    public class SimpleDto
    {
        public string Name { get; set; }

        [JsonProperty("is_admin"), JsonPropertyName("is_admin")]
        [HybridBindProperty(Source.Body)]
        public bool IsAdmin  { get; set; }
    }
}

Every time I do a request I get this behavior:
image

When I remove AddHybridModelBinder from Startup everything works as expected.

Does HybridModelBinding work when used with Newtonsoft.Json?
@billbogaiv your feedback is more than welcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions