다음 json serializaton 설정을 어떻게 추가 할 수 있습니까? TypeNameHandling = TypeNameHandling.All 응답에 $ type 속성이 응답 Json에 추가되도록하려면 어떻게해야합니까?
[HttpGet("GetCustomerById")]
[ProducesResponseType(typeof(CustomerBase), StatusCodes.Status200OK)]
public virtual async Task<ActionResult<CustomerBase>> GetCustomerByIdAsync(int customerId)
{
try
{
if (customerId<= 0)
{
return BadRequest("Invalid customerId in the request.");
}
_logger.LogDebug($"Getting Customer by Id : {CustomerId}");
using (var scope = _serviceScopeFactory.CreateScope())
{
var customer= await scope.ServiceProvider
.GetRequiredService<ICustomerServerApiClient>()
.GetCustomerByIdAsync(CustomerId);
return Ok(customer);
}
}
catch (Exception ex)
{
_logger.LogCritical($"Exception in Get Customer by Id: {CustomerId} " +
$"Returning a 500 to the caller. Exception message: {ex.Message}. " +
$"Stack trace: {ex.StackTrace}.");
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
}
이것이 내 요구 사항을 달성 할 수있는 방법입니다.
//return Ok(customer); replaced by below line
return new JsonResult(customer) { SerializerSettings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All } };
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다