ASP.Net Core 2.2 - separate serializer settings for input and output

前端 未结 2 1165
予麋鹿
予麋鹿 2021-01-24 19:40

ASP.Net Core 2.2 allows to set serializer settings using MvcJsonOptions.SerializerSettings property. The problem is that it affects both input and output. Is there

2条回答
  •  迷失自我
    2021-01-24 20:29

    I would use JsonSerializerSettings class from Newtonsoft.Json to define two instances mySerializeSetting and myDeserializeSettings.

    using Newtonsoft.Json;
    using Microsoft.Rest.Serialization;
    
    string requestContent = SafeJsonConvert.SerializeObject(value, mySerializationSettings);
    

    To deserialize:

    var result = SafeJsonConvert.DeserializeObject(input, myDeserializeSettings);
    

    To see how to set up serialization settings see https://www.newtonsoft.com/json/help/html/SerializationSettings.htm

提交回复
热议问题