Im using this code(C#NETCORE5.0) to return a model:
[HttpPost]
[Authorize(AuthenticationSchemes = "Bearer")]
public IActionResult GetTablero(GenericStringModel item){
TableroVentasManager mng = new TableroVentasManager();
TablaGeneralVentasModel response = mng.getTotalTable(item.zona);
return response != null ? Ok(response) : BadRequest();
}
I want to reduce the size of the response (16.6mb actual) I have use
string ignored = JsonConvert.SerializeObject(response,
Formatting.Indented,
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
but the size increase to 24mb
But if I only return the model, the size is 16.6MB theres a way to ignore null values to reduce the size?
Actual:
{
"zona": "Z305",
"companyId": "C018763",
"formaEnvio": "CCI FORANEO",
"mov": "salesorder",
"tranId": 1193156,
"subTotal": 164.8800,
"consolidado": null,
"nombre": "Ingresado",
"fechaIngreso": "2022-12-02T10:39:56",
"fechaLiberado": null,
"fechaProceso": null,
"fechaCancelado": null,
"consolidado2": 0.0,
"empacado": 0
}
Desired:
{
"zona": "Z305",
"companyId": "C018763",
"formaEnvio": "CCI FORANEO",
"mov": "salesorder",
"tranId": 1193156,
"subTotal": 164.8800,
"nombre": "Ingresado",
"fechaIngreso": "2022-12-02T10:39:56",
"consolidado2": 0.0,
"empacado": 0
}
CodePudding user response:
If response
is a List, can you perhaps use Linq to filter out null values:
response.RemoveAll(x => x == null)
Then return your Ok(response)
CodePudding user response:
I think you can use a compression mechanism something like GZIP
.
After gzip application: