问题
XYZController.cs
[HttpPost]
public async Task<ActionResult> Post([FromBody] T inputContext)
{
var outputContext = Process(inputContext);
return StatusCode(200, outputContext );
}
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddJsonOptions(options =>
{
UpdateJsonSettings.ConfigureJsonFormatter(options.SerializerSettings);
});
}
UpdateJsonSettings.cs
internal static void ConfigureJsonFormatter(JsonSerializerSettings settings)
{
settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
settings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
settings.Converters.Add(new StringEnumConverter());
}
HttpResponse Try 1:
{ "$id": "1", "bill": { "$id": "2", "type": "TYPE1",
HttpResponse Try 2:
{ "$id": "28", <--- NOT SURE WHY ON THE SECOND REQUEST $ID starts with 28 :( --> "bill": { "$id": "29", "type": "TYPE1",
HttpResponse Try 3:
{ "$id": "55", <--- NOT SURE WHY ON THE SECOND REQUEST $ID starts with 55 :( --> "bill": { "$id": "56", "type": "TYPE1",
I am using Newtonsoft.Json (11.0.2)
来源:https://stackoverflow.com/questions/59832635/is-there-a-way-to-reset-id-in-json-response-for-each-http-request