I have a controller that has the following structure/classes:
// model
public class Result
{
public string Document { get; set; } = "";
public int[,] Segments { get; set; } = new int[,] { };
}
// controller
public class SearchController : ControllerBase {
[HttpGet]
[Route("/api/v1/[controller]")]
[Produces("application/json")]
public IActionResult Search(//metadata list)
{
try {
Result result = <service-call-returning Result object>;
return Ok(result);
} catch (Exception e) {
return BadRequest("bad");
}
}
}
It seems that it's not able to serialize the Result object, I am getting the following exception:
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.NotSupportedException: The type 'System.Int32[,]' is not supported.
at System.Text.Json.ThrowHelper.ThrowNotSupportedException_SerializationNotSupported(Type propertyType)
at System.Text.Json.Serialization.Converters.IEnumerableConverterFactory.CreateConverter(Type typeToConvert, JsonSerializerOptions options)
at System.Text.Json.Serialization.JsonConverterFactory.GetConverterInternal(Type typeToConvert, JsonSerializerOptions options)
at System.Text.Json.JsonSerializerOptions.GetConverter(Type typeToConvert)
How do I go about serializing an object with (string, multidimensional array)? Also I have a react app that expects a result, the string is going to be serialized as well (has \n\n \r ....), is it the job for the client app to deserialize it or I need to find a way to return the JSON object as it is non-serialized?