services.AddMvc().AddNewtonsoftJson();
This is not an option for me as I’m using a .net core 5 project. I can add NewtonsoftJson, but not the microsoft core namespace version to configure the service.
So, I’m trying to pass in [FromBody]dynamic, but get serialization errors when trying to deserialize that object into DynamicData. Any suggestions on the best way to Deserialize an object to DynamicData? This is not working - it doesn’t seem to serialize correctly. Again, I would prefer to pass in a dynamic so every form I create doesn’t need a model added to the codebase.
[HttpPost]
[Route("Create/{Schema}")]
public async Task<IActionResult> CreateContent(string Schema, [FromBody]dynamic Data)
{
var serializedData = JsonConvert.DeserializeObject<DynamicData>(Data.ToString());
var created = await _apiClient.CreateContentAsync(Schema, serializedData);
if (created)
return Ok(created);
else
return StatusCode(500);
}
public async Task<bool> CreateContentAsync(string Schema, DynamicData Data, CancellationToken ct = default)
{
try
{
var client = _clientManager.CreateDynamicContentsClient(Schema);
await client.CreateAsync(Data, new ContentCreateOptions() { Publish = false }, null, ct);
return true;
}
catch (Exception ex) {
return false;
}
}
The error is
`{"Squidex Request failed: {\"message\":\"Validation error\",\"traceId\":\"00-fd4bc330cf9e314aaf8c84ccd8178129-f17b2bf17e96ecca-00\",\"type\":\"https://tools.ietf.org/html/rfc7231#section-6.5.1\",\"details\":[\"Unexpected end when deserializing object. Path '', line 7, position 1.\"],\"statusCode\":400}"}`
Incoming JSON is pretty basic at this point.
{
"firstName": "Bobby",
"lastName": "Brown",
"email": "bb@mailinator.com",
"phone": "555-555-5555",
"message": "This is my message!"
}