locked
Jtoken as Post Parameter in aspnet Core 3.1 RRS feed

  • Question

  • User718448626 posted

    I have an application that was written in aspnet core 2.1 and I did an upgrade to core 3.1 the web API failed.  Why is JToken now not valid parameter?  

    // This works on core 2.1 but failed on 3.1

    [HttpPost]
    public async Task<IActionResult> PostAsync([FromBody] JToken value)
    {  

    // code here

      return Ok();

    }

    // This works with Core 3.1

    [HttpPost]
    public async Task<IActionResult> PostAsync([FromBody] JObject jvalue)
    {

    // code here

    return Ok();

    }

    //error return 

    {"errors":{"":["Unexpected character encountered while parsing value: {. Path '', line 1, position 1."]},"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1","title":"One or more validation errors occurred.","status":400,"traceId":"|8ab7b30f-40b939694d56c1ec."}

    Thursday, June 25, 2020 4:08 AM

All replies