Exemplo n.º 1
0
        /// <summary>
        /// Converts serializer settings to Json.Net serialization settings.
        /// </summary>
        ///
        /// <param name="settings">Serializer settings.</param>
        ///
        /// <returns>Json.Net serializer settings.</returns>
        private JsonSerializerSettings ReadSettings(SerializerSettings settings)
        {
            if (settings == null)
            {
                return(null);
            }

            var jsonNetSettings = new JsonSerializerSettings
            {
                NullValueHandling = (bool)settings?.IgnoreNullValues ? NullValueHandling.Ignore : NullValueHandling.Include
            };

            if (settings?.ContractResolver != null)
            {
                jsonNetSettings.ContractResolver = settings.ContractResolver as IContractResolver;
            }

            return(jsonNetSettings);
        }
Exemplo n.º 2
0
 public T Deserialize <T>(string json, SerializerSettings settings = null)
 {
     return(JsonConvert.DeserializeObject <T>(json, ReadSettings(settings)));
 }
Exemplo n.º 3
0
 public string Serialize(object value, SerializerSettings settings = null)
 {
     return(JsonConvert.SerializeObject(value, ReadSettings(settings)));
 }